Skip to content

namedtuple defaults in stubs #1410

@hmc-cs-mdrissi

Description

@hmc-cs-mdrissi
class Foo(NamedTuple):
  x: bool = False

produces an error message similar to,

  File "/Users/pa-loaner/Snapchat/Dev/.venvs/typeshed/lib/python3.9/site-packages/pytype/ast/visitor.py", line 55, in _call_visitor
    return visitor(node)
  File "/Users/pa-loaner/Snapchat/Dev/.venvs/typeshed/lib/python3.9/site-packages/pytype/pyi/parser.py", line 477, in visit_AnnAssign
    raise ParseError(msg)
pytype.pyi.types.ParseError:   File: "stubs/tensorflow/tensorflow/io/__init__.pyi", line 56
    default_value: _TensorCompatible | None = None
   ^
ParseError: Default value for default_value: typing.Union can only be '...', got None

I think it then leads to various noise errors elsewhere due to parse error. Originally hit here by running pytype_test.py stubs/tensorflow/io but you can run pytype_test.py stubs/tensorflow/toy and add a file in toy with just example at top to trigger this error. The error looks to be specific to stub files and normal .py files are fine.

edit: Looking a bit more at code/stacktrace I'm unsure this is unique to namedtuples although probably most common to see default with them in class body.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions