Support Generic
nodes with no type variables
#11906
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.
Resolves #10204.
This is purely a syntax enhancement and requires no changes outside the parser. It is already possible to obtain generic instances that have no type variables even before this PR, such as via
Tuple.new
; even forGeneric
nodes, all instantiations ofNamedTuple
return an empty array in#type_vars
. (In contrast,resolve.type_vars
returns a 1-array of theNamedTuple
orTuple
itself.)At the lexical level, a constant followed by a pair of empty parentheses can currently appear only in the following places:
The formatter removes the parentheses in all these cases. However, if we look at all empty parentheses in general, then we can see that this is not done for
Call
s because they could be incorrectly turned intoVar
s. In this PR the formatter never removes the parentheses in aGeneric
without type variables. Also note that in the following example:the compiler never materializes any
Generic
, because the parser handles this separately in#parse_type_vars
and the correspondingClassDef
/ModuleDef
stores the formal parameters outside the type name.