general: small updates for typing while trying out pyright

This commit is contained in:
Dima Gerasimov 2024-08-27 21:02:39 +01:00 committed by karlicoss
parent b1fe23b8d0
commit c08ddbc781
7 changed files with 12 additions and 14 deletions

View file

@ -133,8 +133,8 @@ def test_classproperty() -> None:
return 'hello'
res = C.prop
assert res == 'hello'
assert_type(res, str)
assert res == 'hello'
# hmm, this doesn't really work with mypy well..

View file

@ -2,7 +2,7 @@
Helpers for hpi doctor/stats functionality.
'''
import collections
import collections.abc
import importlib
import inspect
import typing

View file

@ -25,7 +25,7 @@ def is_not_hpi_module(module: str) -> Optional[str]:
'''
None if a module, otherwise returns reason
'''
import importlib
import importlib.util
path: Optional[str] = None
try:

View file

@ -275,20 +275,18 @@ def test_check_if_hashable() -> None:
x1: List[int] = [1, 2]
r1 = check_if_hashable(x1)
# tgype: ignore[comparison-overlap] # object should be unchanged
assert r1 is x1
assert_type(r1, Iterable[int])
assert r1 is x1
x2: Iterator[Union[int, str]] = iter((123, 'aba'))
r2 = check_if_hashable(x2)
assert list(r2) == [123, 'aba']
assert_type(r2, Iterable[Union[int, str]])
assert list(r2) == [123, 'aba']
x3: Tuple[object, ...] = (789, 'aba')
r3 = check_if_hashable(x3)
# ttype: ignore[comparison-overlap] # object should be unchanged
assert r3 is x3
assert_type(r3, Iterable[object])
assert r3 is x3 # object should be unchanged
x4: List[Set[int]] = [{1, 2, 3}, {4, 5, 6}]
with pytest.raises(Exception):

View file

@ -8,7 +8,6 @@ from pathlib import Path
from datetime import datetime
from html.parser import HTMLParser
from typing import List, Optional, Any, Callable, Iterable, Tuple
from collections import OrderedDict
from urllib.parse import unquote
import pytz
@ -94,8 +93,8 @@ class TakeoutHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
if self.state == State.INSIDE and tag == 'a':
self.state = State.PARSING_LINK
attrs = OrderedDict(attrs)
hr = attrs['href']
[hr] = (v for k, v in attrs if k == '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...
# TODO handle http?

View file

@ -41,6 +41,7 @@ except ModuleNotFoundError as e:
dal = pre_pip_dal_handler('hypexport', e, config, requires=REQUIRES)
DAL = dal.DAL
Highlight = dal.Highlight
Page = dal.Page
@ -49,8 +50,8 @@ def inputs() -> Sequence[Path]:
return get_files(config.export_path)
def _dal() -> dal.DAL:
return dal.DAL(inputs())
def _dal() -> DAL:
return DAL(inputs())
# TODO they are in reverse chronological order...

View file

@ -24,7 +24,7 @@ from datetime import datetime, timezone
from pathlib import Path
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