Skip to content

Commit

Permalink
Fix static typing tests against mypy==0.930
Browse files Browse the repository at this point in the history
  • Loading branch information
brunato committed Dec 23, 2021
1 parent 9dd71b6 commit f114e3e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-xmlschema.yml
Expand Up @@ -53,5 +53,5 @@ jobs:
- name: Lint with mypy
if: ${{ matrix.python-version != 'pypy3' }}
run: |
pip install mypy==0.910 elementpath==2.4.0 lxml-stubs
pip install mypy==0.930 elementpath==2.4.0 lxml-stubs
mypy --show-error-codes --no-warn-unused-ignores xmlschema
6 changes: 3 additions & 3 deletions tox.ini
Expand Up @@ -56,7 +56,7 @@ commands =

[testenv:mypy-py{36,37}]
deps =
mypy==0.910
mypy==0.930
elementpath==2.4.0
lxml-stubs
jinja2
Expand All @@ -65,7 +65,7 @@ commands =

[testenv:mypy-py{38,39,310}]
deps =
mypy==0.910
mypy==0.930
elementpath==2.4.0
lxml-stubs
jinja2
Expand All @@ -89,7 +89,7 @@ deps =
elementpath>=2.4.0, <3.0.0
lxml
jinja2
mypy==0.910
mypy==0.930
lxml-stubs
commands =
pytest tests -ra
Expand Down
2 changes: 1 addition & 1 deletion xmlschema/resources.py
Expand Up @@ -631,7 +631,7 @@ def _lazy_iterparse(self, resource: IO[AnyStr], nsmap: Optional[NsmapType] = Non
root_started = False
nsmap_update = False

_root: ElementType = getattr(self, '_root', None)
_root = cast(Optional[ElementType], getattr(self, '_root', None))

try:
for event, node in tree_iterator:
Expand Down
20 changes: 16 additions & 4 deletions xmlschema/validators/simple_types.py
Expand Up @@ -253,8 +253,14 @@ def simple_type(self) -> 'XsdSimpleType':
def min_value(self) -> Optional[AtomicValueType]:
min_exclusive: Optional['AtomicValueType']
min_inclusive: Optional['AtomicValueType']
min_exclusive = getattr(self.get_facet(XSD_MIN_EXCLUSIVE), 'value', None)
min_inclusive = getattr(self.get_facet(XSD_MIN_INCLUSIVE), 'value', None)
min_exclusive = cast(
Optional['AtomicValueType'],
getattr(self.get_facet(XSD_MIN_EXCLUSIVE), 'value', None)
)
min_inclusive = cast(
Optional['AtomicValueType'],
getattr(self.get_facet(XSD_MIN_INCLUSIVE), 'value', None)
)

if min_exclusive is None:
return min_inclusive
Expand All @@ -269,8 +275,14 @@ def min_value(self) -> Optional[AtomicValueType]:
def max_value(self) -> Optional[AtomicValueType]:
max_exclusive: Optional['AtomicValueType']
max_inclusive: Optional['AtomicValueType']
max_exclusive = getattr(self.get_facet(XSD_MAX_EXCLUSIVE), 'value', None)
max_inclusive = getattr(self.get_facet(XSD_MAX_INCLUSIVE), 'value', None)
max_exclusive = cast(
Optional['AtomicValueType'],
getattr(self.get_facet(XSD_MAX_EXCLUSIVE), 'value', None)
)
max_inclusive = cast(
Optional['AtomicValueType'],
getattr(self.get_facet(XSD_MAX_INCLUSIVE), 'value', None)
)

if max_exclusive is None:
return max_inclusive
Expand Down
5 changes: 3 additions & 2 deletions xmlschema/xpath.py
Expand Up @@ -116,8 +116,9 @@ def __init__(self, schema: Optional[XMLSchemaProtocol] = None,
base_element: Optional[ElementProtocol] = None) -> None:

if schema is None:
from xmlschema import XMLSchema
schema = getattr(XMLSchema, 'meta_schema', None)
from xmlschema import XMLSchema10
schema = cast(XMLSchemaProtocol, getattr(XMLSchema10, 'meta_schema', None))

super(XMLSchemaProxy, self).__init__(schema, base_element)

if base_element is not None:
Expand Down

0 comments on commit f114e3e

Please sign in to comment.