You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow class-based NamedTuple syntax in semantic analyzer for stubs in pre-3.6 mode #3464
This seems to be the relevant code (in mypy/semanal_namedtuple.py):
defcheck_namedtuple_classdef(
self, defn: ClassDef) ->Optional[Tuple[List[str], List[Type], Dict[str, Expression]]]:
"""Parse and validate fields in named tuple class definition. Return a three tuple: * field names * field types * field default values or None, if any of the types are not ready. """ifself.options.python_version< (3, 6):
self.fail('NamedTuple class syntax is only supported in Python 3.6', defn)
return [], [], {}
...
Also, there is is_typeshed_stub_file() in SemanticAnalyzerInterface which isn't quite what we need. A similar property could be added for is_stub_file(), and then the rest should be easy.
Activity
srittau commentedon Oct 7, 2019
Had this come up in python/typeshed#3278.
JukkaL commentedon Oct 7, 2019
This seems to be the relevant code (in
mypy/semanal_namedtuple.py):Also, there is
is_typeshed_stub_file()inSemanticAnalyzerInterfacewhich isn't quite what we need. A similar property could be added foris_stub_file(), and then the rest should be easy.Anybody want to write a PR?
Support NamedTuple class syntax in all stubs
srittau commentedon Oct 7, 2019
PR in #7646.
Support NamedTuple class syntax in all stubs (#7646)
gvanrossum commentedon Oct 7, 2019
Do we know if this is supported by type checkers other than mypy?
srittau commentedon Oct 30, 2019
We checked this in python/typeshed#3321 and pytype, pyre, and pyright, PyCharm, and the Microsoft Language Server for Python all support this.