Skip to content

Commit

Permalink
Closes #2362
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Sep 25, 2022
1 parent 534008b commit 86becb0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ Semantic versioning in our case means:

### Features

- **Breaking**: drops `python3.6` support
- Adds `__init_subclass__` in the beginning of accepted methods
order as per WPS338 #2411

### Bugfixes

- Fixes `WPS226` false positives on `|` use in `SomeType | AnotherType`
type hints syntax
- Now `-1` is not reported to be an overused expression

### Misc

- Adds full violation codes to docs and `BaseViolation.full_code` #2409
Expand All @@ -32,10 +39,6 @@ Semantic versioning in our case means:
- Domain name was changed from `wemake-python-stylegui.de`
to `wemake-python-styleguide.rtfd.io`

### Bugfixes

- Fixes `WPS226` false positives on `|` use in `SomeType | AnotherType` type hints syntax


## 0.16.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def method2(self, arg2: "List[int]") -> 'type.Any':
'{a for a in other}',

# Unary nodes:
'-1', # unary minus operator is raising when used with literal
'+some', # unary plus always raises
'~other',

# Special cases for self:
'self.method([star])', # `[star]` is raising
Expand Down Expand Up @@ -169,6 +169,8 @@ def method2(self, arg2: "List[int]") -> 'type.Any':
'some.prop',
# unary operator
'-value',
'-value.attr',
'-1',
)


Expand Down
12 changes: 6 additions & 6 deletions wemake_python_styleguide/logic/complexity/overuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ def is_unary_minus(node: ast.AST) -> bool:
We use this predicate to allow values
like ``-some_value`` to be overused.
Although negative constants like ``-1``
Although negative constants like ``-5``
should raise violation to force naming them.
"""
if isinstance(node, ast.UnaryOp):
return (
isinstance(node.op, ast.USub) and
not isinstance(node.operand, (Constant, ast.Num))
)
if isinstance(node, ast.UnaryOp) and isinstance(node.op, ast.USub):
# We allow variables, attributes, subscripts, and `-1`
if isinstance(node.operand, (Constant, ast.Num)):
return node.operand.n == 1
return True
return False

0 comments on commit 86becb0

Please sign in to comment.