GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Sentinel and enum type merge issues with generic · Issue #22334 · python/mypy Open Labels bugmypy got something wrongmypy got something wrong Descriptionfrom typing_extensions import sentinel Undefined = sentinel("Undefined") def none_if_undefined[_T](value: _T | Undefined) -> _T | None: return None if value is Undefined else value def func() -> None: device_id: str | Undefined | None = Undefined device_id = none_if_undefined(device_id) # <-- error reveal_type(device_id) test.py:10: error: Argument 1 to "none_if_undefined" has incompatible type "str | Undefined | None"; expected "str | Undefined" [arg-type] test.py:11: note: Revealed type is "str | Undefined | None" However, assigning the result from def func() -> None: device_id: str | Undefined | None = Undefined x = none_if_undefined(device_id) reveal_type(x) device_id = x reveal_type(device_id) test.py:11: note: Revealed type is "str | None" test.py:13: note: Revealed type is "str | None" -- from enum import Enum from typing import Literal class E(Enum): SPECIAL = 1 def none_if_special[_T](value: _T | Literal[E.SPECIAL]) -> _T | None: return None if value is E.SPECIAL else value def func() -> None: device_id: str | Literal[E.SPECIAL] | None = E.SPECIAL device_id = none_if_special(device_id) # <-- error reveal_type(device_id) test.py:12: error: Argument 1 to "none_if_special" has incompatible type "str | Literal[E.SPECIAL] | None"; expected "str | Literal[E.SPECIAL]" [arg-type] test.py:13: note: Revealed type is "str | Literal[test7.E.SPECIAL] | None" -- def none_if_int[_T](value: _T | int) -> _T | None: return None if isinstance(value, int) else value def func() -> None: device_id: str | int | None = 42 device_id = none_if_int(device_id) reveal_type(device_id) Activity
MetadataMetadataAssigneesLabelsbugmypy got something wrongmypy got something wrong ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |