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

Wrong type when accessing some "property" attributes from a TypeVar bounded to type in 1.1.283 #4291

Closed
bellini666 opened this issue Dec 7, 2022 · 4 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@bellini666
Copy link

from typing import TypeVar

_T = TypeVar("_T", bound=type)

def foo(klass: _T):
    reveal_type(klass.__dict__)
    klass.__dict__.get("foo")

The output from this is:

pyright 1.1.283
/tmp/xxx.py
  /tmp/xxx.py:8:17 - information: Type of "klass.__dict__" is "property*"
  /tmp/xxx.py:9:20 - error: Cannot access member "get" for type "property*"
    Member "get" is unknown (reportGeneralTypeIssues)
  /tmp/xxx.py:7:16 - warning: TypeVar "_T" appears only once in generic function signature (reportInvalidTypeVarUse)
1 error, 1 warning, 1 information 
Completed in 0.572sec

This also happens when accessing some other attributes, like __mro__, etc.

@rsokl
Copy link

rsokl commented Dec 8, 2022

This need not involve a TypeVar, the same thing occurs for the annotation klass: type.

rsokl added a commit to mit-ll-responsible-ai/hydra-zen that referenced this issue Dec 8, 2022
rsokl added a commit to mit-ll-responsible-ai/hydra-zen that referenced this issue Dec 8, 2022
@bellini666
Copy link
Author

This need not involve a TypeVar, the same thing occurs for the annotation klass: type.

Oh, you are correct. I tested with Type and the issue did not occur, but it does indeed happens with type

erictraut pushed a commit that referenced this issue Dec 10, 2022
…ype` to a `Callable` and when accessing members from a `type[T]` or a `T` that is bound to `type`. This addresses #4291 and #4258.
@erictraut
Copy link
Collaborator

This will be addressed in the next release.

@erictraut erictraut added bug Something isn't working addressed in next version Issue is fixed and will appear in next published version labels Dec 10, 2022
@erictraut
Copy link
Collaborator

This is included in pyright 1.1.284, 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

3 participants