general: small updates for typing while trying out pyright
This commit is contained in:
parent
b1fe23b8d0
commit
c08ddbc781
7 changed files with 12 additions and 14 deletions
|
@ -133,8 +133,8 @@ def test_classproperty() -> None:
|
||||||
return 'hello'
|
return 'hello'
|
||||||
|
|
||||||
res = C.prop
|
res = C.prop
|
||||||
assert res == 'hello'
|
|
||||||
assert_type(res, str)
|
assert_type(res, str)
|
||||||
|
assert res == 'hello'
|
||||||
|
|
||||||
|
|
||||||
# hmm, this doesn't really work with mypy well..
|
# hmm, this doesn't really work with mypy well..
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Helpers for hpi doctor/stats functionality.
|
Helpers for hpi doctor/stats functionality.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import collections
|
import collections.abc
|
||||||
import importlib
|
import importlib
|
||||||
import inspect
|
import inspect
|
||||||
import typing
|
import typing
|
||||||
|
|
|
@ -25,7 +25,7 @@ def is_not_hpi_module(module: str) -> Optional[str]:
|
||||||
'''
|
'''
|
||||||
None if a module, otherwise returns reason
|
None if a module, otherwise returns reason
|
||||||
'''
|
'''
|
||||||
import importlib
|
import importlib.util
|
||||||
|
|
||||||
path: Optional[str] = None
|
path: Optional[str] = None
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -275,20 +275,18 @@ def test_check_if_hashable() -> None:
|
||||||
|
|
||||||
x1: List[int] = [1, 2]
|
x1: List[int] = [1, 2]
|
||||||
r1 = check_if_hashable(x1)
|
r1 = check_if_hashable(x1)
|
||||||
# tgype: ignore[comparison-overlap] # object should be unchanged
|
|
||||||
assert r1 is x1
|
|
||||||
assert_type(r1, Iterable[int])
|
assert_type(r1, Iterable[int])
|
||||||
|
assert r1 is x1
|
||||||
|
|
||||||
x2: Iterator[Union[int, str]] = iter((123, 'aba'))
|
x2: Iterator[Union[int, str]] = iter((123, 'aba'))
|
||||||
r2 = check_if_hashable(x2)
|
r2 = check_if_hashable(x2)
|
||||||
assert list(r2) == [123, 'aba']
|
|
||||||
assert_type(r2, Iterable[Union[int, str]])
|
assert_type(r2, Iterable[Union[int, str]])
|
||||||
|
assert list(r2) == [123, 'aba']
|
||||||
|
|
||||||
x3: Tuple[object, ...] = (789, 'aba')
|
x3: Tuple[object, ...] = (789, 'aba')
|
||||||
r3 = check_if_hashable(x3)
|
r3 = check_if_hashable(x3)
|
||||||
# ttype: ignore[comparison-overlap] # object should be unchanged
|
|
||||||
assert r3 is x3
|
|
||||||
assert_type(r3, Iterable[object])
|
assert_type(r3, Iterable[object])
|
||||||
|
assert r3 is x3 # object should be unchanged
|
||||||
|
|
||||||
x4: List[Set[int]] = [{1, 2, 3}, {4, 5, 6}]
|
x4: List[Set[int]] = [{1, 2, 3}, {4, 5, 6}]
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
|
|
|
@ -8,7 +8,6 @@ from pathlib import Path
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
from typing import List, Optional, Any, Callable, Iterable, Tuple
|
from typing import List, Optional, Any, Callable, Iterable, Tuple
|
||||||
from collections import OrderedDict
|
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
@ -94,8 +93,8 @@ class TakeoutHTMLParser(HTMLParser):
|
||||||
def handle_starttag(self, tag, attrs):
|
def handle_starttag(self, tag, attrs):
|
||||||
if self.state == State.INSIDE and tag == 'a':
|
if self.state == State.INSIDE and tag == 'a':
|
||||||
self.state = State.PARSING_LINK
|
self.state = State.PARSING_LINK
|
||||||
attrs = OrderedDict(attrs)
|
[hr] = (v for k, v in attrs if k == 'href')
|
||||||
hr = attrs['href']
|
assert hr is not None
|
||||||
|
|
||||||
# sometimes it's starts with this prefix, it's apparently clicks from google search? or visits from chrome address line? who knows...
|
# sometimes it's starts with this prefix, it's apparently clicks from google search? or visits from chrome address line? who knows...
|
||||||
# TODO handle http?
|
# TODO handle http?
|
||||||
|
|
|
@ -41,6 +41,7 @@ except ModuleNotFoundError as e:
|
||||||
dal = pre_pip_dal_handler('hypexport', e, config, requires=REQUIRES)
|
dal = pre_pip_dal_handler('hypexport', e, config, requires=REQUIRES)
|
||||||
|
|
||||||
|
|
||||||
|
DAL = dal.DAL
|
||||||
Highlight = dal.Highlight
|
Highlight = dal.Highlight
|
||||||
Page = dal.Page
|
Page = dal.Page
|
||||||
|
|
||||||
|
@ -49,8 +50,8 @@ def inputs() -> Sequence[Path]:
|
||||||
return get_files(config.export_path)
|
return get_files(config.export_path)
|
||||||
|
|
||||||
|
|
||||||
def _dal() -> dal.DAL:
|
def _dal() -> DAL:
|
||||||
return dal.DAL(inputs())
|
return DAL(inputs())
|
||||||
|
|
||||||
|
|
||||||
# TODO they are in reverse chronological order...
|
# TODO they are in reverse chronological order...
|
||||||
|
|
|
@ -24,7 +24,7 @@ from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import NamedTuple, Iterator, Set, Tuple, Optional, Any, Dict, List
|
from typing import NamedTuple, Iterator, Set, Tuple, Optional, Any, Dict, List
|
||||||
|
|
||||||
from lxml import etree
|
import lxml.etree as etree
|
||||||
|
|
||||||
from my.core.error import Res
|
from my.core.error import Res
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue