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

false positive for new union types #1884

Closed
bo5o opened this issue Feb 18, 2021 · 2 comments · Fixed by #1890
Closed

false positive for new union types #1884

bo5o opened this issue Feb 18, 2021 · 2 comments · Fixed by #1890
Labels
bug Something isn't working help wanted Extra attention is needed level:starter Good for newcomers

Comments

@bo5o
Copy link
Contributor

bo5o commented Feb 18, 2021

Bug report

What's wrong

PEP604 allows | to be used for union types. you can now write str | int instead of Union[str, int] or str | None instead of Optional[str] and even isinstance(foo, str | int) will work. This feature is accepted for Python 3.10, but you can use it already with mypy>=0.800 and from __future__ import annotations (which will become the default in Python 3.10 as well).

However, currently this syntax triggers WPS465.

A workaround is to write type declarations as strings like "str | None" or "str | int".

How it should be

The | operator will be used a lot in future Python versions (e.g. Structural Pattern Matching uses it to define or-patterns). So I think this rule should not cause a violation for these special cases.

System information

OS: Ubuntu 18.04.5 LTS x86_64
Python: 3.7.9
pip: 21.0.1

flake8 information

{
  "dependencies": [],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.7.9",
    "system": "Linux"
  },
  "plugins": [
    {
      "is_local": false,
      "plugin": "flake8-bandit",
      "version": "2.1.2"
    },
    {
      "is_local": false,
      "plugin": "flake8-broken-line",
      "version": "0.3.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-bugbear",
      "version": "20.11.1"
    },
    {
      "is_local": false,
      "plugin": "flake8-comprehensions",
      "version": "3.3.1"
    },
    {
      "is_local": false,
      "plugin": "flake8-darglint",
      "version": "1.6.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-debugger",
      "version": "4.0.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-docstrings",
      "version": "1.5.0, pydocstyle: 5.1.1"
    },
    {
      "is_local": false,
      "plugin": "flake8-eradicate",
      "version": "1.0.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-pytest-style",
      "version": "1.3.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-string-format",
      "version": "0.3.0"
    },
    {
      "is_local": false,
      "plugin": "flake8_commas",
      "version": "2.0.0"
    },
    {
      "is_local": false,
      "plugin": "flake8_isort",
      "version": "4.0.0"
    },
    {
      "is_local": false,
      "plugin": "flake8_quotes",
      "version": "3.2.0"
    },
    {
      "is_local": false,
      "plugin": "logging-format",
      "version": "0.6.0"
    },
    {
      "is_local": false,
      "plugin": "mccabe",
      "version": "0.6.1"
    },
    {
      "is_local": false,
      "plugin": "naming",
      "version": "0.11.1"
    },
    {
      "is_local": false,
      "plugin": "pycodestyle",
      "version": "2.6.0"
    },
    {
      "is_local": false,
      "plugin": "pyflakes",
      "version": "2.2.0"
    },
    {
      "is_local": false,
      "plugin": "rst-docstrings",
      "version": "0.0.14"
    },
    {
      "is_local": false,
      "plugin": "wemake_python_styleguide",
      "version": "0.15.0"
    }
  ],
  "version": "3.8.4"
}
@bo5o bo5o added the bug Something isn't working label Feb 18, 2021
@sobolevn
Copy link
Member

Oh wow! Thanks for the report! I was not aware that this is already possible. 👍

@sobolevn sobolevn added help wanted Extra attention is needed level:starter Good for newcomers labels Feb 18, 2021
@sobolevn
Copy link
Member

Btw, PRs are welcome!

bo5o added a commit to bo5o/wemake-python-styleguide that referenced this issue Feb 20, 2021
bo5o added a commit to bo5o/wemake-python-styleguide that referenced this issue Feb 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed level:starter Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants