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-104683: Argument clinic: remove the LandMine class #107541

Merged
merged 1 commit into from Aug 1, 2023

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Aug 1, 2023

In Converter.__init__, self.function is temporarily set to be an instance of LandMine, for reasons explained in this comment:

cpython/Tools/clinic/clinic.py

Lines 2847 to 2853 in 6ef8f8c

# this is deliberate, to prevent you from caching information
# about the function in the init.
# (that breaks if we get cloned.)
# so after this change we will noisily fail.
self.function: Function | LandMine = LandMine(
"Don't access members of self.function inside converter_init!"
)

However, this approach leads to some complicated typing elsewhere in clinic: there are several places where we had to add assert isinstance(self.function, Function) assertions in order to keep mypy happy when adding type annotations to clinic.py. An approach that works just as well, and makes mypy much more happy, is to delay setting self.function at all until after converter_init() has run. We can improve the error message if somebody does try to access self.function inside a converter_init() method by adding a __getattr__ method that catches the resulting AttributeError and adds to the error message the line number in the clinic input that caused clinic to fail.

Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Choose a reason for hiding this comment

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

Looks good to me; good riddance :)

@AlexWaygood AlexWaygood merged commit 030f6b1 into python:main Aug 1, 2023
25 checks passed
@AlexWaygood AlexWaygood deleted the delete-LandMine branch August 1, 2023 20:17
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.

None yet

3 participants