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 — Narrowing types to `Literal` using `in` syntax · Issue #12535 · python/mypy Open Labels DescriptionTake this example code: x = "a" reveal_type(x) assert x in ("a", "b", "c") reveal_type(x) y = 20 reveal_type(y) assert y == 10 or y == 20 or y == 50 reveal_type(y) The current output of this is: $ mypy x.py x.py:2: note: Revealed type is "builtins.str" x.py:4: note: Revealed type is "builtins.str" x.py:7: note: Revealed type is "builtins.int" x.py:9: note: Revealed type is "builtins.int" If mypy were to support type narrowing using chained $ mypy x.py x.py:4: note: Revealed type is "builtins.str" x.py:6: note: Revealed type is "Union[Literal['a'], Literal['b'], Literal['c']]" x.py:9: note: Revealed type is "builtins.int" x.py:11: note: Revealed type is "Union[Literal[10], Literal[20], Literal[50]]" I think doing simple narrowing here would be relatively easy and very useful. Reacted by Michael Joseph Rosenthal, Marc Mueller, Brenton Partridge, Huon Wilson, Alex Waygood, Matan Gover, Gideon, Marti Raudsepp, Stanislav Terliakov, Justin Black and 23 more Activity
MetadataMetadataAssigneesLabelsProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — 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. |