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

Using a pipe symbol in typing.Literal string #16368

Closed
haakonvt opened this issue Oct 29, 2023 · 4 comments
Closed

Using a pipe symbol in typing.Literal string #16368

haakonvt opened this issue Oct 29, 2023 · 4 comments
Labels
bug mypy got something wrong topic-literal-types topic-pep-604 PEP 604 (union | operator)

Comments

@haakonvt
Copy link

Bug Report

Using mypy 1.6.1, I'm unable to use a pipe symbol in a string used in typing.Literal:

To Reproduce

from typing import Literal

def fn(x: Literal["foo", "bar", "foo|bar"]) -> None:
    reveal_type(x)

Expected Behavior
No issue with "foo|bar".

Actual Behavior

This gives the following output:

bb_mypy.py:4: error: Name "foo" is not defined  [name-defined]
    def fn(x: Literal["foo", "bar", "foo|bar"]) -> None:
                                    ^
bb_mypy.py:5: note: Revealed type is "Any"
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Python version used: 3.8.18
  • Mypy version used: 1.6.1
  • Mypy command-line flags: None were used.
  • Mypy configuration options from mypy.ini (and other config files):
  1. pretty = true
  2. check_untyped_defs = true
  3. ignore_missing_imports = false
  4. disallow_untyped_defs = true
  5. follow_imports = normal
  6. namespace_packages = true
  7. explicit_package_bases = true
  8. show_error_codes = true
  9. plugins = numpy.typing.mypy_plugin
  10. no_implicit_reexport = true
  11. no_implicit_optional = true
  12. warn_redundant_casts = true
  13. warn_unused_ignores = true
@haakonvt haakonvt added the bug mypy got something wrong label Oct 29, 2023
@AlexWaygood AlexWaygood added topic-literal-types topic-pep-604 PEP 604 (union | operator) labels Oct 30, 2023
@AlexWaygood
Copy link
Member

Duplicate of #16367

@AlexWaygood AlexWaygood marked this as a duplicate of #16367 Oct 30, 2023
@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Oct 30, 2023
@haakonvt
Copy link
Author

haakonvt commented Oct 30, 2023

Duplicate of #16367

I'd argue #16367 is a duplicate of this one (as I was the one to discover it) and the other was created while I slowly typed this issue up 😅 But nevermind!

@AlexWaygood
Copy link
Member

I'd argue #16367 is a duplicate of this one (as I was the one to discover it) and the other was created while I slowly typed this issue up 😅 But nevermind!

It's a dog-eat-dog world out here on the mypy issue tracker, I'm afraid ;)

@InSyncWithFoo
Copy link
Contributor

InSyncWithFoo commented Nov 1, 2023

Sorry :) I was about to let you know before creating this issue, but you posted this comment saying that you would "open an issue if this question does not receive a possible workaround/solution within a few days".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-literal-types topic-pep-604 PEP 604 (union | operator)
Projects
None yet
Development

No branches or pull requests

3 participants