gh-104683: Argument clinic: remove the LandMine class
#107541
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In
Converter.__init__,self.functionis temporarily set to be an instance ofLandMine, for reasons explained in this comment:cpython/Tools/clinic/clinic.py
Lines 2847 to 2853 in 6ef8f8c
However, this approach leads to some complicated typing elsewhere in
clinic: there are several places where we had to addassert isinstance(self.function, Function)assertions in order to keep mypy happy when adding type annotations toclinic.py. An approach that works just as well, and makes mypy much more happy, is to delay settingself.functionat all until afterconverter_init()has run. We can improve the error message if somebody does try to accessself.functioninside aconverter_init()method by adding a__getattr__method that catches the resultingAttributeErrorand adds to the error message the line number in theclinicinput that causedclinicto fail.Tools/clinic/#104683