Skip to content

Commit

Permalink
Fix typing issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Jul 6, 2023
1 parent 5575d58 commit d7304fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fido2/ctap2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def args(*params) -> Dict[int, Any]:
class _CborDataObject(_DataClassMapping[int]):
@classmethod
def _get_field_key(cls, field: Field) -> int:
return fields(cls).index(field) + 1
return fields(cls).index(field) + 1 # type: ignore


@dataclass(eq=False, frozen=True)
Expand Down
13 changes: 6 additions & 7 deletions fido2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
Any,
TypeVar,
Hashable,
ClassVar,
Dict,
get_type_hints,
)
import struct
Expand Down Expand Up @@ -208,11 +206,12 @@ def _parse_value(t, value):


class _DataClassMapping(Mapping[_T, Any]):
__dataclass_fields__: ClassVar[Dict[str, Field[Any]]]
# TODO: This requires Python 3.9, and fixes the tpye errors we now ignore
# __dataclass_fields__: ClassVar[Dict[str, Field[Any]]]

def __post_init__(self):
hints = get_type_hints(type(self))
for f in fields(self):
for f in fields(self): # type: ignore
value = getattr(self, f.name)
if value is None:
continue
Expand All @@ -230,7 +229,7 @@ def _get_field_key(cls, field: Field) -> _T:
raise NotImplementedError()

def __getitem__(self, key):
for f in fields(self):
for f in fields(self): # type: ignore
if key == self._get_field_key(f):
value = getattr(self, f.name)
serialize = f.metadata.get("serialize")
Expand All @@ -248,7 +247,7 @@ def __getitem__(self, key):
def __iter__(self):
return (
self._get_field_key(f)
for f in fields(self)
for f in fields(self) # type: ignore
if getattr(self, f.name) is not None
)

Expand All @@ -268,7 +267,7 @@ def from_dict(cls, data: Optional[Mapping[_T, Any]]):
)

kwargs = {}
for f in fields(cls):
for f in fields(cls): # type: ignore
key = cls._get_field_key(f)
if key in data:
value = data[key]
Expand Down

0 comments on commit d7304fa

Please sign in to comment.