Another fix for mypy 1.12

This commit is contained in:
Kovid Goyal 2024-10-15 08:16:31 +05:30
parent 46c610525c
commit a81fd3b1c2
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -2,6 +2,7 @@
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
import errno
import inspect
import io
import json
import os
@ -287,7 +288,7 @@ def asdict(self, keep_defaults: bool = False) -> dict[str, Union[str, int, bytes
val = getattr(self, k.name)
if not keep_defaults and val == k.default:
continue
if issubclass(k.type, Enum):
if inspect.isclass(k.type) and issubclass(k.type, Enum):
val = val.name
ans[k.name] = val
return ans
@ -310,7 +311,7 @@ def get_serialized_fields(self, prefix_with_osc_code: bool = False) -> Iterator[
found = True
yield nts[name]
yield '='
if issubclass(k.type, Enum):
if inspect.isclass(k.type) and issubclass(k.type, Enum):
yield val.name
elif k.type is bytes:
yield base64_encode(val)
@ -337,7 +338,7 @@ def handle_item(key: memoryview, val: memoryview) -> None:
field = fmap.get(key)
if field is None:
return
if issubclass(field.type, Enum):
if inspect.isclass(field.type) and issubclass(field.type, Enum):
setattr(ans, field.name, field.type[str(val, "utf-8")])
elif field.type is bytes:
setattr(ans, field.name, base64_decode(val))