Skip to content

Commit d05d746

Browse files
committed
Fix type hinting for ErrorPolicy's children
Type hint Type[ErrorPolicy] was not resoling correctly for its children.
1 parent a6cdd0f commit d05d746

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2929
- Race condition in `test_types_repository_separation` - Martin Miksik
3030
- Import error while using python version prior to 3.7 - Martin Miksik
3131
- Parsing datetime containing timezone information for python 3.6 and lower - Martin Miksik
32+
- Type hinting for ErrorPolicy's children - Martin Miksik
3233

3334
## [1.3.0]
3435

pyodata/config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" Contains definition of configuration class for PyOData"""
22

33
from typing import Type, Dict
4-
from pyodata.policies import PolicyFatal, ParserError, ErrorPolicy
4+
from pyodata.policies import PolicyFatal, ParserError, ErrorPolicyType
55
import pyodata.version
66

77

@@ -14,8 +14,8 @@ class Config:
1414

1515
def __init__(self,
1616
odata_version: Type[pyodata.version.ODATAVersion],
17-
custom_error_policies=None,
18-
default_error_policy=None,
17+
custom_error_policies: Dict[ParserError, ErrorPolicyType] = None,
18+
default_error_policy: ErrorPolicyType = None,
1919
xml_namespaces=None
2020
):
2121

@@ -48,19 +48,19 @@ def __init__(self,
4848
self._annotation_namespaces = None
4949
self._aliases: Dict[str, str] = dict()
5050

51-
def err_policy(self, error: ParserError) -> ErrorPolicy:
51+
def err_policy(self, error: ParserError) -> ErrorPolicyType:
5252
""" Returns error policy for given error. If custom error policy fo error is set, then returns that."""
5353
if self._custom_error_policy is None:
5454
return self._default_error_policy
5555

5656
return self._custom_error_policy.get(error, self._default_error_policy)
5757

58-
def set_default_error_policy(self, policy: ErrorPolicy):
58+
def set_default_error_policy(self, policy: ErrorPolicyType):
5959
""" Sets default error policy as well as resets custom error policies"""
6060
self._custom_error_policy = None
6161
self._default_error_policy = policy
6262

63-
def set_custom_error_policy(self, policies: Dict[ParserError, Type[ErrorPolicy]]):
63+
def set_custom_error_policy(self, policies: Dict[ParserError, ErrorPolicyType]):
6464
""" Sets custom error policy. It should be called only after setting default error policy, otherwise
6565
it has no effect. See implementation of "set_default_error_policy" for more details.
6666
"""

pyodata/policies.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
from abc import ABC, abstractmethod
88
from enum import Enum, auto
9+
from typing import TypeVar
910

1011

1112
class ParserError(Enum):
@@ -22,6 +23,9 @@ class ParserError(Enum):
2223
COMPLEX_TYPE = auto()
2324

2425

26+
ErrorPolicyType = TypeVar("ErrorPolicyType", bound="ErrorPolicy")
27+
28+
2529
class ErrorPolicy(ABC):
2630
""" All policies has to inhere this class"""
2731
@abstractmethod

0 commit comments

Comments
 (0)