Skip to content

Harden mypy configuration - #1455

Merged
joshuagl merged 5 commits into
theupdateframework:developfrom
jku:mypy-tweaks
Jul 2, 2021
Merged

joshuagl merged 5 commits into
theupdateframework:developfrom
jku:mypy-tweaks

Conversation

@jku

@jku jku commented Jun 17, 2021 •

Copy link
Copy Markdown
Member

We can almost enable "strict = True" already but

  • we should decide if we really want to do that (what strict means may change when mypy updates)
  • we're not quite there yet...

So fix a few issues and harden the mypy configuration where possible.

The one remaining possibly interesting option (that is currently included in "strict") is:

  • no_any_return: seems to require securesystemslib.formats annotations (or specifying some types in tuf code that calls securesystemslib)

@sechkova sechkova left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the only way to find out what will be applied with the strict flag is to check mypy --strict on the current version ...

Anyway, I approve extending the list and see where this will lead us to.

Jussi Kukkonen added 5 commits June 23, 2021 10:51
unrecognized_fields is always initialized

Signed-off-by: Jussi Kukkonen <[email protected]>
We're quite close to being able to enable only "strict = True" but not
quite there. In the mean time enable some useful individual settings.

disallow_untyped_defs:
    report an error whenever code contains a function definition
    without type annotations
warn_redundant_casts:
    report an error whenever code uses an unnecessary cast
warn_unused_ignores:
    report an error whenever code uses an unnecessary # type: ignore
    comment
warn_unreachable:
    report an error whenever code is determined to be unreachable or
    redundant

Signed-off-by: Jussi Kukkonen <[email protected]>
exceptions.py is used from metadata.py: Annotating it is required if we
want to enable "no_untyped_call" in mypy.

The only change is UnsignedMetadataError: I would have removed argument
"signable" altogether but figured this is not worth breaking API. So
now "signable" is still not used for anything but it is now optional.

Signed-off-by: Jussi Kukkonen <[email protected]>
report an error whenever a function with type annotations calls a
function defined without annotations.

Also include exceptions.py in mypy checks.

Signed-off-by: Jussi Kukkonen <[email protected]>
@jku

jku commented Jun 23, 2021

Copy link
Copy Markdown
Member Author

rebased on develop, no changes

@joshuagl joshuagl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

We can almost enable "strict = True" already but

we should decide if we really want to do that (what strict means may change when mypy updates)

We should notice when the definition of strict changes thanks to CI, but could always pin mypy version and review updates for changes to the definition of strict?

Comment thread tuf/exceptions.py
"""Indicate metadata object with insufficient threshold of signatures."""

def __init__(self, message, signable):
# signable is not used but kept in method signature for backwards compat

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want a FIXME or similar here? So that we are reminded to remove this unused variable before we tag 1.0?

@joshuagl
joshuagl merged commit 7815f05 into theupdateframework:develop Jul 2, 2021
@jku
jku deleted the mypy-tweaks branch December 30, 2024 09:09
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.

3 participants