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

PEP 696 false positive when used with a class with no __new__ #4417

Closed
erictraut opened this issue Jan 7, 2023 · 2 comments
Closed

PEP 696 false positive when used with a class with no __new__ #4417

erictraut opened this issue Jan 7, 2023 · 2 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@erictraut
Copy link
Collaborator

When a generic class uses default TypeVar types and provides an __init__ but no __new__ method, pyright computes an incorrect specialization type for the constructor call.

from dataclasses import dataclass
from typing import TypeAlias


class Commentable: ...

class User(Commentable): ...
class ClientUser(Commentable): ...

Authors: TypeAlias = User | ClientUser
@dataclass
class Comment[OwnerT: Commentable = Commentable, AuthorT: Authors = Authors]:
    author: AuthorT
    owner: OwnerT

our_user = ClientUser()

def post_comment[OwnerT: Commentable](owner: OwnerT) -> Comment[OwnerT, ClientUser]:
    return Comment(author=our_user, owner=owner)
@erictraut erictraut added the bug Something isn't working label Jan 7, 2023
erictraut pushed a commit that referenced this issue Jan 7, 2023
…g a constructor on a class that uses new PEP 696 TypeVar defaults and provides an `__init__` but no `__new__`. This addresses #4417.
@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Jan 7, 2023
@erictraut
Copy link
Collaborator Author

@Gobot1234, this will be fixed in the next release.

@erictraut
Copy link
Collaborator Author

This is addressed in pyright 1.1.288, which I just published. It will also be included in a future release of pylance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant