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

Type of type incorrectly narrowed to type[object] #9656

Closed
matejcik opened this issue Jan 3, 2025 · 2 comments
Closed

Type of type incorrectly narrowed to type[object] #9656

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

Comments

@matejcik
Copy link

matejcik commented Jan 3, 2025

If I call issubclass on an unbound type variable (or type[Any]), then the else-branch will narrow it to type[object].
This will then cause an error when using my_type(somevalue) to instantiate that type.

def get_type() -> type:
    return int

my_type = get_type()

reveal_type(my_type)  # -> type
if issubclass(my_type, str):
    print("weird")
else:
    reveal_type(my_type)  # -> type[object]
    foobar = my_type(42)

output:

/home/matejcik/test.py
  /home/matejcik/test.py:6:13 - information: Type of "my_type" is "type"
  /home/matejcik/test.py:10:17 - information: Type of "my_type" is "type[object]"
  /home/matejcik/test.py:11:22 - error: Expected 0 positional arguments (reportCallIssue)
1 error, 0 warnings, 2 informations 

VS Code extension or command-line
VScode extension in current version and pyright 1.1.391

@matejcik matejcik added the bug Something isn't working label Jan 3, 2025
@erictraut
Copy link
Collaborator

I think that narrowing to type[object] is technically correct in this case, but I agree that it would be better to evaluate to type[Unknown] (or just type which is equivalent).

erictraut added a commit that referenced this issue Jan 14, 2025
…e when the subject type is `type` or `Any`. This addresses #9656.
erictraut added a commit that referenced this issue Jan 14, 2025
…e when the subject type is `type` or `Any`. This addresses #9656. (#9704)
@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Jan 14, 2025
@erictraut
Copy link
Collaborator

This is addressed in pyright 1.1.392.

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

2 participants