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

A question about type narrowing #5274

Closed
uf-fipper opened this issue Dec 18, 2023 · 2 comments
Closed

A question about type narrowing #5274

uf-fipper opened this issue Dec 18, 2023 · 2 comments
Assignees
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@uf-fipper
Copy link

pylance version: 2023.12.1

Look at the following code:

from typing import TypeAlias, TypeVar

IntOrStr: TypeAlias = int | str
IntOrStrT = TypeVar("IntOrStrT", bound=IntOrStr)

def func(a: IntOrStrT) -> IntOrStrT:
    if isinstance(a, int):
        ...
        a.as_integer_ratio  # Cannot access member "as_integer_ratio" for type "str*"
    else:
        ...
    return a

image

There is an error at line a.as_integer_ratio: Cannot access member "as_integer_ratio" for type "str*". Is this normal? There is no error in version 2023.11.10.

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Dec 18, 2023
@erictraut
Copy link
Contributor

This has been fixed in a newer version of pyright (the type checker upon which pylance is built). If you switch to the prerelease version of pylance, the error should go away.

@heejaechang heejaechang added fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed needs repro Issue has not been reproduced yet labels Jan 8, 2024
@heejaechang
Copy link
Contributor

fixed in 2023.12.100 preview.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants