Skip to content
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

Add type annotations [WIP] #360

Closed

Conversation

sveinse
Copy link
Collaborator

@sveinse sveinse commented Apr 4, 2023

With reference to discussion in #358, this PR adds typing annotations to canopen.

As of today, this branch is still work in progress and the annotation is not yet complete.

mypy is the primary type checker, however as [my] development is done in VSCode, the code is linted against pyright/pylance.

Closes #358

@christiansandberg
Copy link
Owner

What happens if you add mypy to GitHub actions (.github/workflows/pythonpackage.yml)? Does it pass or are there more things that need fixing?

@sveinse
Copy link
Collaborator Author

sveinse commented Apr 8, 2023

There are still some mypy issues remaining:

canopen\objectdictionary\__init__.py:527: error: Invalid index type "List[int]" for "Dict[str, List[int]]"; expected type "str"  [index]
canopen\objectdictionary\__init__.py:538: error: Invalid index type "List[int]" for "Dict[str, List[int]]"; expected type "str"  [index]
canopen\variable.py:194: error: Incompatible types in assignment (expression has type "List[int]", variable has type "range")  [assignment]
canopen\variable.py:208: error: Argument 1 to "iter" has incompatible type "Dict[str, List[int]]"; expected "SupportsIter[Iterator[int]]"  [arg-type]
canopen\pdo\base.py:100: error: Cannot find implementation or library stub for module named "canmatrix"  [import]
canopen\pdo\base.py:100: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
canopen\pdo\base.py:115: error: Incompatible types in assignment (expression has type "float", variable has type "Optional[int]")  [assignment]
canopen\pdo\base.py:117: error: Incompatible types in assignment (expression has type "float", variable has type "Optional[int]")  [assignment]
canopen\objectdictionary\eds.py:54: error: "ObjectDictionary" has no attribute "__edsFileInfo"  [attr-defined]
canopen\objectdictionary\eds.py:321: error: "Variable" has no attribute "default_raw"; maybe "default"?  [attr-defined]
canopen\objectdictionary\eds.py:322: error: "Variable" has no attribute "default_raw"; maybe "default"?  [attr-defined]
canopen\objectdictionary\eds.py:330: error: "Variable" has no attribute "value_raw"  [attr-defined]
canopen\objectdictionary\eds.py:427: error: "ObjectDictionary" has no attribute "__edsFileInfo"  [attr-defined]
Found 12 errors in 4 files (checked 28 source files)

These are related to Bits, PdoBase.export() which depend on unknown canmatrix, and the injection of __edsFileInfo attr in objectdictionary.eds.import_eds(). Ref my long comment in #358 , these are questions I need some guidance/discussion on how to solve.

It is probably a great idea to incorporate mypy checks into GH actions workflow, but it is not yet implemented.

@sveinse
Copy link
Collaborator Author

sveinse commented Jun 19, 2024

I don't plan to implement this PR. Instead the type annotations will be split up into multiple PRs of suitable chunks which makes it easier to review. Closing this PR.

@sveinse sveinse closed this Jun 19, 2024
@sveinse sveinse deleted the feature-type-annotation branch July 9, 2024 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type annotations in canopen
2 participants