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

Fix or suppress MyPy errors #336

Merged
merged 29 commits into from
May 13, 2024
Merged

Fix or suppress MyPy errors #336

merged 29 commits into from
May 13, 2024

Conversation

Codeglitches
Copy link
Contributor

@Codeglitches Codeglitches commented Jan 21, 2024

As discussed in #335 the code currently does not fair well when the types are analyzed by MyPy. This pull request makes some changes so that it does pass a MyPy analysis check without errors. This would be a good starting point to start working on adding Annotations throughout the code.

Not all errors are really solved. In a few places a dynamic code style is used or there is some type confusion. These errors that could not be solved without some more refactoring are suppressed using the # type: ignore comment.

Let me know what you think of the changes

All annotations need to be suppressed however, as they are seen as int
@chrysn
Copy link
Owner

chrysn commented May 6, 2024

Thanks, that's a useful contribution; still looking through it.

Testing locally, mypy complains about cbor2 missing annotations (Skipping analyzing "cbor2": module is installed, but missing library stubs or py.typed marker). Were you using any particular branch thereof? (I tried with having the whl built from latest cbor2 master in my PYTHONPATH).

If I want to test this in CI, is there anything more than mypy aiocoap to test? (answered already in #335 (comment))

I've recently dropped support for Python 3.7, 3.8 and 3.9; did you apply any workarounds to support type checking in old versions, or is that something that rather happens on the boxes of developers anyway, where a recent Python is present (and at runtime on older Pythons, type information is discarded)?

This reverts a regression on setting per-remote-instance
maximum_block_size_exp introduced in 8c8bb73.
@chrysn
Copy link
Owner

chrysn commented May 6, 2024

Apart from the experiments in #347, I've pushed some more changes:

  • AIU Any is frowned upon; I think I found the right types to go there.
  • I've merged in master, which also gives it a shot at CI

@chrysn
Copy link
Owner

chrysn commented May 7, 2024

To summarize the current state, there are two things I'd like to do differently still:

  • Wherever lists of things are spelled out rather than done programmatically, there should be an if __debug__: guarded check that verifies them, and possibly offers code generation
  • There are some large swaths of type: ignore that I'll go through, maybe I can provide better hints
  • The enum situation could need enhancement, optionnumbers are becoming unsightly

Sorry for the delay in taking this up; are you still around and would you address those?

@chrysn
Copy link
Owner

chrysn commented May 11, 2024

The enum rework of #347 appears to work, allowing the enum definitions to themselves to stay easy -- one down.

@chrysn
Copy link
Owner

chrysn commented May 11, 2024

The one large copied list is now also verified, and I'm in the process of looking through the remaining ignores.

@chrysn
Copy link
Owner

chrysn commented May 12, 2024

... and the large swaths are fixed by overhauling typing in oscore (where this exercise actually helped find a bug).

Running a few last checks, but then I think this can go in together with #347.

chrysn added a commit that referenced this pull request May 13, 2024
This includes some non-trivial changes in how attributes are exposed and
how enums are generated, none of which should have publicly observable
effects unless the behavior was unreliable already.

Notable changes include:

* ExtensibleIntEnum types (Code, ContentFormat) are now based on
  Python's `enum.Enum`.
* Group OSCORE: Fixed crash when attempting to use cipher suite that
  does not support all modes.
* OSCORE contexts' `external_aad_is_group` property was replaced with
  subclassing `ContextWhereExternalAadIsGroup`

Merges: #336
Merges: #347
@chrysn chrysn merged commit 5c9fded into chrysn:master May 13, 2024
@Codeglitches
Copy link
Contributor Author

Thanks for merging this pull request. Sorry for not lending a hand on finishing it up properly; I was otherwise occupied.

@Codeglitches Codeglitches deleted the support-mypy branch May 24, 2024 11:37
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.

2 participants