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

Annotate hash module #970

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

jku
Copy link
Collaborator

@jku jku commented Mar 15, 2025

I'd like to statically analyze calls to securesystemslib in other projects

  • securesystemslib needs a py.typed file for that
  • securesystemslib.hash is the only core module that is not annotated
  • securesystemslib.hash cannot really be properly annotated but we can pretend (to enable static analysis of other parts of the code like Signer

Changelog:

  • Add py.typed
  • refactor mypy config into pyproject.toml
  • make mypy config stricter but don't try to lint tests with it
  • Run lint on oldest supported python version to let mypy find annotation issues on that python
  • Annotate hash module. The only code change is using hashlib.blake2b() instead of hashlib.new() for the 256bit blake2b
  • Fix a bunch of mall annotation issues elsewhere in code: the only noteworthy change is FileSystemBackend.__new__(): theoretically an API change but I don't think object.__new__() takes extra args so I doubt it was ever used.

@lukpueh
Copy link
Member

lukpueh commented Mar 17, 2025

This PR is not just about hash module, right? Also, what's missing for marking this ready for review?

@jku
Copy link
Collaborator Author

jku commented Mar 17, 2025

This PR is not just about hash module, right?

yeah there's refactor (and tightening) of mypy config and minor annotation fixes that result from that

Also, what's missing for marking this ready for review?

possibly just fixing the PR message?

@jku jku marked this pull request as ready for review March 18, 2025 09:08
jku added 3 commits March 18, 2025 11:56
* Move config to pyproject.toml
* Turn on useful mypy options
* Don't check tests with mypy: too much to fix right now
* Add py.typed to announce this project is type annotated
* Fix various annotation issues

Issues remain in hash module

Signed-off-by: Jussi Kukkonen <[email protected]>
It's not really possible to annotate hash correctly but let's do
something...

Signed-off-by: Jussi Kukkonen <[email protected]>
This is useful since it will notice use of too new futures (or lack of
"from __future__ import annotations").

Signed-off-by: Jussi Kukkonen <[email protected]>
@jku
Copy link
Collaborator Author

jku commented Mar 18, 2025

Only change in this force-push is that FilesystemBackend.__new__() signature now remains compatible with what it was: I just used more "typing.Any".

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