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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not check | in type hints in WPS226 #2495

Merged
merged 3 commits into from Sep 23, 2022

Conversation

dolfinus
Copy link
Contributor

@dolfinus dolfinus commented Sep 16, 2022

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)
  • I have created at least one test case for the changes I have made
  • I have updated the documentation for the changes I have made
  • 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.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good idea!

@codecov
Copy link

codecov bot commented Sep 16, 2022

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.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dolfinus
Copy link
Contributor Author

PR is approved, how about merging?

@sobolevn sobolevn merged commit 45cd76a into wemake-services:master Sep 23, 2022
@dolfinus dolfinus deleted the bugfix/WPS226 branch September 23, 2022 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants