Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NamedTuple no longer includes ellipsis for fields with default values #15638

Closed
ericstarr opened this issue Jul 11, 2023 · 1 comment · Fixed by #15680
Closed

NamedTuple no longer includes ellipsis for fields with default values #15638

ericstarr opened this issue Jul 11, 2023 · 1 comment · Fixed by #15680
Assignees
Labels
bug mypy got something wrong topic-stubgen

Comments

@ericstarr
Copy link

ericstarr commented Jul 11, 2023

Bug Report

In the past, stubgen would indicate NamedTuple fields with default values using an ellipsis. Now it does not indicate which fields have default values in any way. I don't know exactly what version I used to generate my old stubs, but it was about 2 years ago.

To Reproduce

Run stubgen on a python file containing the following

from typing import NamedTuple

class Spam(NamedTuple):
    a: int
    b: int = 1

Expected Behavior

The generated stub should look like

from typing import NamedTuple

class Spam(NamedTuple):
    a: int
    b: int = ...

Actual Behavior

The generated stub looks like

from typing import NamedTuple

class Spam(NamedTuple):
    a: int
    b: int

Your Environment

  • Mypy version used: 1.4.1
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.9
@ericstarr ericstarr added the bug mypy got something wrong label Jul 11, 2023
@sobolevn
Copy link
Member

sobolevn commented Jul 15, 2023

This was not specific for named tuples, it was a general logic for all class level assigns: https://github.com/python/mypy/blob/v0.750/mypy/stubgen.py#L981-L982

But, I agree that it makes the difference for named tuples:

from typing import NamedTuple

class A(NamedTuple):
    x: int = 1
class B(NamedTuple):
    x: int

A()
B()  # E: Missing positional argument "x" in call to "B"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-stubgen
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants