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

narrow literal types #717

Open
KotlinIsland opened this issue Jul 23, 2024 · 1 comment · May be fixed by #812 or #852
Open

narrow literal types #717

KotlinIsland opened this issue Jul 23, 2024 · 1 comment · May be fixed by #812 or #852
Labels

Comments

@KotlinIsland
Copy link
Owner

KotlinIsland commented Jul 23, 2024

a = "is this a joke"
reveal_type(a)  # str

b: str
assert b == "is this a joke"
reveal_type(b)  # str
@DetachHead
Copy link
Collaborator

it should also narrow in cases like this:

from typing import Literal

value: str

assert value == "asdf" # not sure about this because __eq__ can be overridden
assert value is "asdf" # but this one should definitely work

foo: Literal["asdf"] = value # error: Incompatible types in assignment (expression has type "str", variable has type "Literal['asdf']") 

@KotlinIsland KotlinIsland added the p-1 high label Oct 20, 2024
This was referenced Nov 6, 2024
@KotlinIsland KotlinIsland linked a pull request Jan 2, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants