Repository navigation
PEP 695: Rename typeparams to type_params in AST #104656
Description
Activity
Reposting my comment in #104642 (comment) here, for visibility:
Nearly all other attributes on AST nodes in Python use snake_case --
type_ignores,decorator_list,end_lineno,type_comment,end_col_offset,format_spec,is_async,kw_defaults,context_expr,optional_vars,kwd_attrs,kwd_patterns. And the attribute onTypeAliases, functions and classes at runtime is__type_params__, not__typeparams__.There's a few examples of smushedtogethercase attributes on AST nodes --
finalybody,kwonlyargs,vararg,asname. But they're definitely in the minority.I would greatly prefer it if this attribute was renamed to be
type_params.The same goes for the
typeparamtype in the AST. Naming ittype_paramwould be consistent with e.g.type_ignore.I'm working on a draft PR.
Reacted by Alex Waygood- added a commit that references this issue
on May 19, 2023 From a users perspective either works fine. It would be more important to not change it unnecessarily after it has been released. I.e. I wouldn't recommend to go back and "fix"
finalybody,kwonlyargs, etc.Reacted by Alex Waygood, sunmy2019 and Jelle Zijlstra@erictraut, I think we'd be especially interested in your thoughts on this as the author of the PEP, since
typeparamsis clearly specified by the PEP as the name for these nodes. Would you object to this change?I don't have a strong opinion one way or the other on the AST names. I tried to follow the patterns I could see when I implemented my prototype. If there are some other conventions or precedents that I missed, I have no objections to changing these names.
Reacted by Alex Waygood, sunmy2019 and Marc MuellerI'm in favor of including the
_becauserunonwords_are_less_readable.Reacted by Alex Waygood, Jelle Zijlstra, Oleg Iarygin and Carl MeyerUnless someone disagrees strongly I'll merge the change to
type_paramstonight, in time for the beta tomorrow.Reacted by Alex WaygoodWewilluseunderscores.
PEP-695 introduces a few new AST attributes that are currently called
typeparams, as specified in https://peps.python.org/pep-0695/#ast-changes. However, @AlexWaygood rightly points out (#104642 (comment)) thattype_paramswould be more readable and in line with most of the rest of the AST. Should we change it?cc @erictraut for this PEP, @cdce8p who made some AST changes in this area before, @pablogsal @isidentical as AST experts.
Linked PRs