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

Improve checks for PEP 604 - alternative Union syntax #4065

Closed
cdce8p opened this issue Feb 3, 2021 · 0 comments · Fixed by #4075
Closed

Improve checks for PEP 604 - alternative Union syntax #4065

cdce8p opened this issue Feb 3, 2021 · 0 comments · Fixed by #4075
Labels

Comments

@cdce8p
Copy link
Member

cdce8p commented Feb 3, 2021

Is your feature request related to a problem?

Pylint should be able to detect if PEP 604 (alternative Union Syntax) is used inappropriately.
The PEP will be implemented in 3.10, so the following should emit error messages in versions 3 - 3.9:

Alias = str | int  # Should be an error

var: str | int  # Should be an error

def func(arg: int | str):  # Should be an error
    pass

def func2() -> int | str:  # Should be an error
    pass

Each line is a TypeError in Python, eg:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    Alias = str | int
TypeError: unsupported operand type(s) for |: 'type' and 'type'

With postponed evaluation of annotations enabled (3.7 - 3.9)

from __future__ import annotations

Alias = str | int  # Should be an error

var: str | int

def func(arg: int | str):
    pass

def func2() -> int | str:
    pass

Only the alias definition is evaluated directly and thus an error.

Current situation

No errors are emitted, even in versions prior to 3.10 and without the future import.

--
https://www.python.org/dev/peps/pep-0604/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants