Skip to content

1.1.384 forbids ellipsis defaults in NamedTuple stubs #9191

@srittau

Description

@srittau

Describe the bug

Cf. python/typeshed#12764. When trying to update pyright from 1.1.383 to 1.1.384 in typeshed, it reports NamedTuples that use ellipses as defaults:

class ToCPlaceholder(NamedTuple):
    render_function: Callable[[FPDF, Any], object]
    start_page: int
    y: int
    pages: int = ...

Causes:

/home/runner/work/typeshed/typeshed/stubs/fpdf2/fpdf/fpdf.pyi
/home/runner/work/typeshed/typeshed/stubs/fpdf2/fpdf/fpdf.pyi:97:18 - error: Type "EllipsisType" is not assignable to declared type "int"
"EllipsisType" is not assignable to "int" (reportAssignmentType)

Similar to function defaults, NamedTuples can have complex defaults that can't be represented statically in stubs and should use an ellipsis instead.

In [1]: from typing import NamedTuple
In [2]: x = 42
In [3]: class Foo(NamedTuple):
   ...:     a: int
   ...:     b: int = x
   ...: 
In [4]: Foo(12)
Out[4]: Foo(a=12, b=42)

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't workingregression

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions