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

gh-104050: Argument clinic: Add annotations to the LandMine class #104648

Closed
wants to merge 2 commits into from

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented May 19, 2023

When type checkers see that a class has a __getattr__ or __getattribute__ method, they'll assume that there are things going on with that class that are too magical for them to understand. As such, they will refrain from emitting any errors relating to setting or retrieving attributes from instances of that class. That's basically the opposite of what we want here (there'll be a runtime exception from any attribute access on an instance of LandMine). As such, it's much better to pretend to the type checkers that the __getattribute__ method doesn't exist.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Yes, good hack!

@AlexWaygood
Copy link
Member Author

AlexWaygood commented May 21, 2023

This is the best thing to do if we want to have strict typing in clinic.py, but I wonder if we do? The original motivation for adding type hints was to improve maintainability and readability, and this change possibly works against that. The original justification for running a type checker in CI was to have a means of verifying the accuracy of the annotations we were adding, not necessarily because we wanted the code to be strictly type-checked.

Thoughts @erlend-aasland? I don't want to be introducing "typing hacks" into clinic.py if you disagree with the principle :)

@erlend-aasland
Copy link
Contributor

Strict type-checking is not a goal at the moment. I agree that this does not contribute to increased readability, so I say we drop it.

@AlexWaygood
Copy link
Member Author

Strict type-checking is not a goal at the moment. I agree that this does not contribute to increased readability, so I say we drop it.

Sounds good. Thanks!

@AlexWaygood AlexWaygood deleted the argclinic-getattrs branch May 21, 2023 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants