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

Complete coverage for the qrcode package #12675

Merged
merged 5 commits into from
Sep 20, 2024

Conversation

mjpieters
Copy link
Contributor

@mjpieters mjpieters commented Sep 17, 2024

This PR covers all of the project. This library is somewhat underdocumented so
I erred on the side of covering all modules with public names.

Without this PR, the hints are partly broken; we have experienced these specific issues in production code:

  • The QRCode() overload fails to match when trying to use one of the qrcode.constants.ERROR_CORRECT_* constants for error_correction and providing an image_factory value, due to the use of Literal[]
  • The RoundedModuleDrawer radius_ratio argument is incorrectly typed as int (probably based on the default value, it should be a float).

This comment has been minimized.

@mjpieters mjpieters force-pushed the types-qrcode-complete branch 3 times, most recently from d454e5b to 50c3950 Compare September 17, 2024 20:12

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

Thanks! Not a complete review, but we require Anys to be documented (either using a comment or using an appropriate type alias). I noticed that you added Any annotations to a few kwargs arguments which are - I suspect - forwarded to another function. In this case, we could copy the arguments over (or leave kwargs unannotated for now).

@mjpieters
Copy link
Contributor Author

Thanks! Not a complete review, but we require Anys to be documented (either using a comment or using an appropriate type alias). I noticed that you added Any annotations to a few kwargs arguments which are - I suspect - forwarded to another function. In this case, we could copy the arguments over (or leave kwargs unannotated for now).

I'll review these again and document where I can. I certainly may have missed some forwarded calls in this project.

However, there are some bad practices in the codebase, like a ABCs with an empty (non-abstract) __init__ method with **kwargs and no types. I think I may just remove these from the annotations instead.

This comment has been minimized.

@srittau
Copy link
Collaborator

srittau commented Sep 18, 2024

However, there are some bad practices in the codebase, like a ABCs with an empty (non-abstract) init method with **kwargs and no types. I think I may just remove these from the annotations instead.

You could either remove them if you think that no valid code should call __init__ with arguments, or you could use _typeshed.Unused to mark that fact.

@mjpieters
Copy link
Contributor Author

You could either remove them if you think that no valid code should call __init__ with arguments, or you could use _typeshed.Unused to mark that fact.

The project isn't that well structured, I am not confident enough to say it'll never be called with arguments. So I removed it from the type hints altogether.

This comment has been minimized.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

Thanks, a few notes below, mostly around using IO and its sub-classes. These are semi-deprecated in typeshed, especially in argument types, since these types are not protocols and very wide.

stubs/qrcode/qrcode/base.pyi Show resolved Hide resolved
stubs/qrcode/qrcode/image/pil.pyi Outdated Show resolved Hide resolved
stubs/qrcode/qrcode/image/pure.pyi Outdated Show resolved Hide resolved
stubs/qrcode/qrcode/image/styledpil.pyi Outdated Show resolved Hide resolved
stubs/qrcode/qrcode/image/styledpil.pyi Outdated Show resolved Hide resolved
stubs/qrcode/qrcode/image/styles/colormasks.pyi Outdated Show resolved Hide resolved
stubs/qrcode/qrcode/main.pyi Outdated Show resolved Hide resolved

This comment has been minimized.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau merged commit bde71c5 into python:main Sep 20, 2024
48 checks passed
@mjpieters mjpieters deleted the types-qrcode-complete branch September 20, 2024 14:24
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