Skip to content

Commit

Permalink
Update type annotations and mypy tests settings
Browse files Browse the repository at this point in the history
  • Loading branch information
brunato committed Apr 28, 2022
1 parent 6243143 commit 0e33927
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-elementpath.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
if: ${{ matrix.python-version != '3.7' && matrix.python-version == 'pypy-3.8' }}
run: |
pip install mypy==0.950
mypy --show-error-codes elementpath
mypy --show-error-codes --strict elementpath
- name: Test with unittest
run: |
pip install lxml xmlschema>=1.9.0
Expand Down
4 changes: 2 additions & 2 deletions elementpath/regex/unicode_subsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def __eq__(self, other: object) -> bool:
else:
return self._codepoints == other

def __ior__(self, other: object) -> 'UnicodeSubset': # type: ignore[override]
def __ior__(self, other: object) -> 'UnicodeSubset':
if not isinstance(other, Iterable):
return NotImplemented
elif isinstance(other, UnicodeSubset):
Expand Down Expand Up @@ -376,7 +376,7 @@ def __and__(self, other: object) -> 'UnicodeSubset':
obj = self.copy()
return obj.__iand__(other)

def __ixor__(self, other: object) -> 'UnicodeSubset': # type: ignore[override]
def __ixor__(self, other: object) -> 'UnicodeSubset':
if other is self:
self.clear()
return self
Expand Down
2 changes: 1 addition & 1 deletion elementpath/tdop.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def wrong_value(self, message: str = 'invalid value') -> ValueError:

class ParserMeta(ABCMeta):

token_base_class: Type[Token[Any]]
token_base_class: Type[Any]
literals_pattern: Pattern[str]
name_pattern: Pattern[str]
tokenizer: Optional[Pattern[str]]
Expand Down
3 changes: 3 additions & 0 deletions elementpath/xpath30/xpath30_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ def parse_datetime_marker(marker: str, dt: datetime.datetime, lang: Optional[str
else:
zero_cp, zero_ch = ord('0'), '0'

min_width: int
max_width: Optional[int]

digits = sum(c.isdigit() for c in presentation)
opt_digits = presentation.count('#')
if not width or width == '*':
Expand Down
4 changes: 2 additions & 2 deletions elementpath/xpath_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from itertools import chain
from types import ModuleType
from typing import TYPE_CHECKING, cast, Dict, Any, List, Iterator, \
Optional, Sequence, Union, Callable, MutableMapping, Set, Tuple
Optional, Sequence, Union, Callable, MutableMapping, Set

from .exceptions import ElementPathTypeError, ElementPathValueError
from .namespaces import XML_NAMESPACE
Expand Down Expand Up @@ -586,7 +586,7 @@ def iter_descendants(self, axis: Optional[str] = None,
In this case set the context size at start and change both position and \
item at each iteration. For default only context item is changed.
"""
descendants: Union[Iterator[Union[XPathNodeType, None]], Tuple[XPathNode]]
descendants: Any
with_self = axis != 'descendant'

if self.item is None:
Expand Down
1 change: 0 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
[mypy]
show_error_codes = True
warn_unused_ignores = True
9 changes: 8 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ deps =
commands =
flake8 elementpath

[testenv:mypy-py{37,38,39,310}]
[testenv:mypy-py37]
deps =
mypy==0.950
commands =
mypy --config-file {toxinidir}/mypy.ini elementpath
python tests/test_typing.py

[testenv:mypy-py{38,39,310}]
deps =
mypy==0.950
commands =
mypy --config-file {toxinidir}/mypy.ini --strict elementpath
python tests/test_typing.py

[testenv:coverage]
commands =
coverage run -p -m unittest
Expand Down

0 comments on commit 0e33927

Please sign in to comment.