-
Notifications
You must be signed in to change notification settings - Fork 7
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
full typing with mypy #16
Conversation
This is good work to increase confidence in correctness! |
Ok great then I can continue. What do you think should be the minimum Python version in 2024? (looks like 3.8 from the tests) I need to make sure the typing syntax is compatible with the minimum supported Python version. |
I like to support all python versions, also supported by cpython, which is currently >=3.8. |
cmake_file_api/kinds/cache/v2.py
Outdated
__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": |
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
cmake_file_api/kinds/cache/v2.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Also, does the dikt
need a more specialized typing annotation?
e.g. dict[str, object]
?
I see you've changed it into dict[str, Any]
in other locations.
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.
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 comment
The 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.
Here are the last remaining issues with mypy strict mode, they are a bit tougher to resolve. Any suggestions? ~/PycharmProjects/python-cmake-file-api py-typed !9 ?1 ❯ mypy --install-types --non-interactive --strict 🐍 python-cmake-file-api-3.10 17:30:38
cmake_file_api/kinds/configureLog/target/v2.py:496: error: Argument 4 to "CodemodelTargetV2" has incompatible type "BacktraceNode | None"; expected "BacktraceNode" [arg-type]
cmake_file_api/kinds/codemodel/target/v2.py:297: error: Argument 2 to "TargetCompileGroupPCH" has incompatible type "Any | None"; expected "BacktraceNode" [arg-type]
cmake_file_api/kinds/codemodel/target/v2.py:320: error: Argument 2 to "TargetCompileGroupDefine" has incompatible type "Any | None"; expected "BacktraceNode" [arg-type]
cmake_file_api/kinds/codemodel/target/v2.py:497: error: Argument 4 to "CodemodelTargetV2" has incompatible type "Any | None"; expected "BacktraceNode" [arg-type]
cmake_file_api/reply/v1/api.py:54: error: "object" has no attribute "keys" [attr-defined]
cmake_file_api/reply/v1/api.py:78: error: "object" has no attribute "get" [attr-defined]
cmake_file_api/reply/v1/api.py:81: error: Returning Any from function declared to return "CMakeFilesV1 | None" [no-any-return]
cmake_file_api/reply/v1/api.py:87: error: Need type annotation for "result" (hint: "result: dict[<type>, <type>] = ...") [var-annotated]
cmake_file_api/reply/v1/api.py:89: error: "object" has no attribute "get" [attr-defined]
Found 9 errors in 3 files (checked 38 source files) |
I will look into these asap. |
Hi @madebr , could you give some feedback on the findings? I can fix them myself if needed |
I see one remaining typing bug, but don't know how to address the others. --- a/cmake_file_api/kinds/configureLog/target/v2.py
+++ b/cmake_file_api/kinds/configureLog/target/v2.py
@@ -434,7 +434,7 @@ class CodemodelTargetV2:
"isGeneratorProvided", "install", "link", "archive", "dependencies", "sources",
"sourceGroups", "compileGroups")
- def __init__(self, name: str, id: str, type: TargetType, backtrace: BacktraceNode, folder: Optional[Path],
+ def __init__(self, name: str, id: str, type: TargetType, backtrace: Optional[BacktraceNode], folder: Optional[Path],
paths: CMakeSourceBuildPaths, nameOnDisk: str, artifacts: list[Path],
isGeneratorProvided: Optional[bool], install: Optional[TargetInstall],
link: Optional[TargetLink], archive: Optional[TargetArchive], |
@madebr everything fixed up and ready to go :) |
Thanks for the non-trivial fix :) I just pushed v0.0.8, which will be available on pypi soon |
currently work in progress, let me know if you are interested in continued work on this @madebr
About 19 findings are outstanding, maybe some more if we turn on strict mode