gh-104683: Argument clinic: remove some unnecessary uses of self.next()
in the DSLParser
#107635
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.
Many
state_foo
methods on theDSLParser
class inclinic.py
are called only indirectly via thenext()
method:cpython/Tools/clinic/clinic.py
Lines 4645 to 4652 in 407d7fd
The reason for this is that the
DSLParser
parses argument-clinic input a line at a time; butstate
often persists across lines. (Example: a docstring can span multiple lines; by saving the "state" at the end of one line, the DSLParser is able to resume parsing with the same state when it begins parsing the next line, and therefore knows that it's in the middle of a docstring.)However, there are two
state_foo
methods on theDSLParser
class that are arguably badly named, and shouldn't be called viaself.next()
, even though they both currently are:state_modulename_name
state_parameter_docstring_start
Both of these are examples of states that are impossible to span multiple lines. A modulename declaration cannot span multiple lines; nor can the start of a parameter docstring. As such, calling these methods via
self.next()
is needless indirection, and can be removed.It is provable that both of these states cannot span multiple lines, due to the fact that neither
state_modulename_name
norstate_parameter_docstring_start
ever exit early before settingself.state
to something new (by callingself.next
).Tools/clinic/
#104683