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

[stubgen] Add required ... rhs to NamedTuple fields with default values #15680

Merged
merged 4 commits into from
Jul 28, 2023

Conversation

sobolevn
Copy link
Member

Closes #15638

@sobolevn sobolevn changed the title Add required ... rhs to NamedTuple fields with default values [stubgen] Add required ... rhs to NamedTuple fields with default values Jul 15, 2023
Copy link
Member Author

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After your review, I've noticed that the test case is broken. I was testing it locally with stubgen ex.py && bat out/ex.pyi and it all worked correctly.

For example, stubgen for this file:

# ex.py
from typing import NamedTuple

class A(NamedTuple):
    x: int
    y: str = 'a'

class B(A):
    z1: str
    z2 = 1

class RegularClass:
    x: int
    y: str = 'a'
    class NestedNamedTuple(NamedTuple):
        x: int
        y: str = 'a'

class NamedTupleWithNestedClass(NamedTuple):
    class Nested:
        x: int
        y: str = 'a'

Produces the following .pyi file:

from typing import NamedTuple

class A(NamedTuple):
    x: int
    y: str = ...

class B(A):
    z1: str
    z2: int

class RegularClass:
    x: int
    y: str
    class NestedNamedTuple(NamedTuple):
        x: int
        y: str = ...

class NamedTupleWithNestedClass(NamedTuple): ...

But, here's what is produced with our test case:

from typing import NamedTuple

class A(NamedTuple):
    x: int
    y: str

class B(A):                                   
    z1: str
    z2: int

class RegularClass:
    x: int
    y: str
    class NestedNamedTuple(NamedTuple):
        x: int
        y: str

class NamedTupleWithNestedClass(NamedTuple):
    class Nested:
        x: int
        y: str

Two changes in tests:

  1. = ... is missing
  2. class Nested: ... is present

What is going on? :)

@sobolevn
Copy link
Member Author

Ok, I need [case testNamedTupleClassSyntax_semanal] :)

@sobolevn
Copy link
Member Author

I've created a new issue about nested classes in NamedTuples: #15752

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM other than my nit about the test

test-data/unit/stubgen.test Outdated Show resolved Hide resolved
@sobolevn sobolevn merged commit a8467c4 into master Jul 28, 2023
13 checks passed
@sobolevn sobolevn deleted the issue-15638 branch July 28, 2023 11:59
sobolevn added a commit that referenced this pull request Jul 29, 2023
This is a test case for #15680 from
`stubtest`'s point of view.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NamedTuple no longer includes ellipsis for fields with default values
3 participants