wemake-python-styleguide
wemake-python-styleguide copied to clipboard
Do not check | in type hints in WPS226
I have made things!
In my project I use a lot of new-style annotations - Type1 | Type2 instead of Union[Type1, Type2] provided by Python 3.10. To get these annotations work on previous Python versions (e.g. 3.7) I use from __future__ import annotations, which converts all type hints to strings, so it is actually stored in __annotations__ like "Type1 | Type2".
If module contains a lot of optional annotations, such as:
class MyClass:
field1: int | None
field2: str | None
fiels3: datetime | int | None
...
class MyClass2(MyClass):
fiels4: SomeType | None
and so on, WPS226 starts to fail:
WPS226 Found string literal over-use: |
In this PR I've added | literal to list of ignored strings which should fix the issue.
Checklist
- [X I have double checked that there are no unrelated changes in this pull request (old patches, accidental config files, etc)
- [X] I have created at least one test case for the changes I have made
- [X] I have updated the documentation for the changes I have made
- [X] I have added my changes to the
CHANGELOG.md
Related issues
🙏 Please, if you or your company is finding wemake-python-styleguide valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/wemake-python-styleguide. As a thank you, your profile/company logo will be added to our main README which receives hundreds of unique visitors per day.
Codecov Report
Merging #2495 (8b43691) into master (8f95f17) will not change coverage. The diff coverage is
n/a.
@@ Coverage Diff @@
## master #2495 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 120 120
Lines 6422 6422
Branches 1447 1447
=========================================
Hits 6422 6422
| Impacted Files | Coverage Δ | |
|---|---|---|
| ...hon_styleguide/visitors/ast/complexity/overuses.py | 100.00% <ø> (ø) |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
PR is approved, how about merging?