-
Notifications
You must be signed in to change notification settings - Fork 7
full typing with mypy #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
6986528
69bebb7
36c9fc9
3d6d088
9b866d2
e6037da
38a8e98
1fcd7d7
d6bf9e0
9095b18
a8c32cc
95c3c3a
d982884
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
/build/ | ||
/.eggs/ | ||
/venv/ | ||
/.venv | ||
*.egg-info | ||
*.py[co] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,15 @@ class CacheEntryType(Enum): | |
TYPE_UNINITIALIZED = "UNINITIALIZED" | ||
|
||
|
||
class CacheEntryProperty(object): | ||
class CacheEntryProperty: | ||
__slots__ = ("name", "value") | ||
|
||
def __init__(self, name: str, value: str): | ||
self.name = name | ||
self.value = value | ||
|
||
@classmethod | ||
def from_dict(cls, dikt: Dict) -> "CacheEntryProperty": | ||
def from_dict(cls, dikt: dict) -> "CacheEntryProperty": | ||
name = dikt["name"] | ||
value = dikt["value"] | ||
return cls(name, value) | ||
|
@@ -38,17 +38,17 @@ def __repr__(self) -> str: | |
) | ||
|
||
|
||
class CacheEntry(object): | ||
class CacheEntry: | ||
__slots__ = ("name", "value", "type", "properties") | ||
|
||
def __init__(self, name: str, value: str, type: CacheEntryType, properties: List[CacheEntryProperty]): | ||
def __init__(self, name: str, value: str, type: CacheEntryType, properties: list[CacheEntryProperty]): | ||
self.name = name | ||
self.value = value | ||
self.type = type | ||
self.properties = properties | ||
|
||
@classmethod | ||
def from_dict(cls, dikt: Dict) -> "CacheEntry": | ||
def from_dict(cls, dikt: dict) -> "CacheEntry": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, does the I see you've changed it into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, needs to be changed everywhere to comply. Long-term it would be great to replace the Any as well, perhaps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When/if that becomes possible, you'd effectively replace a lot of work these classes do. |
||
name = dikt["name"] | ||
value = dikt["value"] | ||
type = CacheEntryType(dikt["type"]) | ||
|
@@ -65,25 +65,25 @@ def __repr__(self) -> str: | |
) | ||
|
||
|
||
class CacheV2(object): | ||
class CacheV2: | ||
KIND = ObjectKind.CACHE | ||
|
||
__slots__ = ("version", "entries") | ||
|
||
def __init__(self, version: VersionMajorMinor, entries: List[CacheEntry]): | ||
def __init__(self, version: VersionMajorMinor, entries: list[CacheEntry]): | ||
self.version = version | ||
self.entries = entries | ||
|
||
@classmethod | ||
def from_dict(cls, dikt: Dict, reply_path) -> "CacheModelV2": | ||
def from_dict(cls, dikt: dict, reply_path) -> "CacheV2": | ||
if dikt["kind"] != cls.KIND.value: | ||
raise ValueError | ||
version = VersionMajorMinor.from_dict(dikt["version"]) | ||
entries = list(CacheEntry.from_dict(ce) for ce in dikt["entries"]) | ||
return cls(version, entries) | ||
|
||
@classmethod | ||
def from_path(cls, path: Path, reply_path: Path) -> "CacheModelV2": | ||
def from_path(cls, path: Path, reply_path: Path) -> "CacheV2": | ||
dikt = json.load(path.open()) | ||
return cls.from_dict(dikt, reply_path) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's now possible to remove the unused typing imports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done