[Playground](https://mypy-play.net/?mypy=master&python=3.12&flags=strict&gist=df978698d4904f2fd0cd5a0beb66f196): ```python from typing import Literal def f(v: Literal['foo', 'bar', 'foo|bar']) -> None: ... ``` Expected behavior: ```python f('foo') # Pass f('bar') # Pass f('foo|bar') # Pass f('baz') # Fail f('foo|') # Fail f('|qux') # Fail f('foo|qux') # Fail ``` Actual behaviour: ```py def f(v: Literal['foo', 'bar', 'foo|bar']) -> None: # error: Name "foo" is not defined [name-defined] ... ``` Environment: - Mypy version used: 1.4/1.5/1.6/master branch. - Mypy command-line flags: None. - Mypy configuration options from `mypy.ini` (and other config files): None. - Python version used: 3.8/3.9/3.10/3.11/3.12. This bug is found by StackOverflow user [Håkon T.](https://stackoverflow.com/users/3887338/h%c3%a5kon-t) at [this question](https://stackoverflow.com/q/77385142). It seems that mypy would try to interpret any string containing a pipe (`|`) as a type, and in this case it failed.