8000 Exclude irrelevant members in `narrow_declared_type` from union overlapping with enum by sterliakov · Pull Request #18897 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Exclude irrelevant members in narrow_declared_type from union overlapping with enum #18897

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

Merged
merged 6 commits into from
Apr 11, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove error from the test again, fixed separately
  • Loading branch information
sterliakov committed Apr 9, 2025
commit ac0d9cb51ee01852beb9741d466d94080edec66a
17 changes: 8 additions & 9 deletions test-data/unit/check-typeguard.test
Original file line number Diff line number Diff line change
Expand Up @@ -807,16 +807,16 @@ def test() -> None:
[case testTypeGuardedTypeDoesNotLeak]
# https://github.com/python/mypy/issues/18895
from enum import Enum
from typing import Union
from typing_extensions import TypeGuard, Literal
from typing import Literal, Union
from typing_extensions import TypeGuard

class Model(str, Enum):
MODEL_A1 = 'model_a1'
MODEL_A2 = 'model_a2'
MODEL_B = 'model_b'
A1 = 'model_a1'
A2 = 'model_a2'
B = 'model_b'

MODEL_A = Literal[Model.MODEL_A1, Model.MODEL_A2]
MODEL_B = Literal[Model.MODEL_B]
MODEL_A = Literal[Model.A1, Model.A2]
MODEL_B = Literal[Model.B]

def is_model_a(model: str) -> TypeGuard[MODEL_A]:
return True
Expand All @@ -829,7 +829,6 @@ def process_model(model: Union[MODEL_A, MODEL_B]) -> int:

def handle(model: Model) -> int:
if is_model_a(model) or is_model_b(model):
# TODO: should start passing after #18896
return process_model(model) # E: Argument 1 to "process_model" has incompatible type "Model"; expected "Union[Literal[Model.MODEL_A1, Model.MODEL_A2], Literal[Model.MODEL_B]]"
return process_model(model)
return 0
[builtins fixtures/tuple.pyi]
0