Skip to content

Update mypy Workaround if It Is No Longer Needed #3

@mcdonnnj

Description

@mcdonnnj

💡 Summary

We currently work around a perceived issue with type hinting with mypy in:

# mypy relies on typeshed (https://github.com/python/typeshed) for
# stdlib type hinting, but it does not have the correct type hints for
# hashlib.new(). The PR I submitted to fix them
# (https://github.com/python/typeshed/pull/4973) was approved, but I
# am not sure if mypy will still have issues with the usage of this
# keyword in non Python 3.9 (when the usedforsecurity kwarg was added)
# environments. I believe the earliest I can test this will be in mypy
# v0.900, and I have made
# https://github.com/cisagov/hash-http-content/issues/3 to document
# the status of this workaround.
# hasher = hashlib.new(hash_algorithm, usedforsecurity=False)
hasher = getattr(hashlib, "new")(hash_algorithm, usedforsecurity=False)

After a new version of mypy with type hint updates (possibly v0.900) is released, we should see if this workaround is still necessary to pass linting.

Motivation and context

Workarounds should only be used as long as there is something to work around.

Implementation notes

The preferred usage is commented out, so testing is simple as switching between the current and preferred usage.

Acceptance criteria

  • mypy hook passes with the preferred usage in place
  • Code is updated

or

  • mypy hook still fails with the preferred usage in place
  • Comment is updated to reflect the necessity of the workaround

Metadata

Metadata

Assignees

No one assigned

    Labels

    improvementThis issue or pull request will add new or improve existing functionalityneed infoThis issue or pull request requires further information

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions