Skip to content

Commit

Permalink
Fixed #2577 (#2594)
Browse files Browse the repository at this point in the history
* Fixed #2577

* try to fix docs post_install

* updated formatter output files

* got back ipynb

* empty string fix

* removed safety
  • Loading branch information
Roxe322 committed Mar 21, 2023
1 parent 936715d commit 4cb5a65
Show file tree
Hide file tree
Showing 8 changed files with 966 additions and 995 deletions.
4 changes: 1 addition & 3 deletions .readthedocs.yml
Expand Up @@ -13,9 +13,7 @@ build:
- asdf global poetry latest
- poetry config virtualenvs.create false
post_install:
- |
. "$(pwd | rev | sed 's/stuokcehc/svne/' | rev)/bin/activate"
&& poetry install --only main --only docs
- . "$(pwd | rev | sed 's/stuokcehc/svne/' | rev)/bin/activate" && poetry install --only main --only docs

sphinx:
configuration: 'docs/conf.py'
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -30,6 +30,7 @@ Semantic versioning in our case means:
- Make `generic_visit()` check script properly handle `with` statements.
- Allow calling magic methods with the same name as the enclosing method #2381
- Fix WrongEmptyLinesCountViolation false positive #2531
- Fix OpenWithoutContextManagerViolation false positive #2577

### Misc

Expand Down
1 change: 0 additions & 1 deletion Makefile
Expand Up @@ -17,7 +17,6 @@ unit:
package:
poetry run poetry check
poetry run pip check
poetry run safety check --full-report

.PHONY: test
test: lint unit package
1,870 changes: 913 additions & 957 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pyproject.toml
Expand Up @@ -83,7 +83,6 @@ hypothesmith = "^0.2"

mypy = "^0.982"

safety = "^2.2"
autopep8 = "^1.7"
import-linter = "^1.2"

Expand Down
64 changes: 32 additions & 32 deletions tests/test_formatter/snapshots/snap_test_formatter_output.py
Expand Up @@ -70,37 +70,37 @@
\x1b[4m\x1b[1m./tests/fixtures/formatter/formatter1.py\x1b[0m\x1b[0m
1:1 WPS111 Found too short name: s < 2
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
1:7 WPS110 Found wrong variable name: handle
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
2:21 WPS432 Found magic number: 200
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
2:21 WPS303 Found underscored number: 2_00
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
\x1b[4m\x1b[1m./tests/fixtures/formatter/formatter2.py\x1b[0m\x1b[0m
1:1 WPS110 Found wrong variable name: data
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
1:10 WPS110 Found wrong variable name: param
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
2:12 WPS437 Found protected attribute usage: _protected
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
2:31 WPS303 Found underscored number: 10_00
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
Full list of violations and explanations:
Expand Down Expand Up @@ -136,37 +136,37 @@
\x1b[4m\x1b[1m./tests/fixtures/formatter/formatter1.py\x1b[0m\x1b[0m
1:1 WPS111 Found too short name: s < 2
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
1:7 WPS110 Found wrong variable name: handle
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
2:21 WPS432 Found magic number: 200
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
2:21 WPS303 Found underscored number: 2_00
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
\x1b[4m\x1b[1m./tests/fixtures/formatter/formatter2.py\x1b[0m\x1b[0m
1:1 WPS110 Found wrong variable name: data
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
1:10 WPS110 Found wrong variable name: param
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
2:12 WPS437 Found protected attribute usage: _protected
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
2:31 WPS303 Found underscored number: 10_00
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
\x1b[1mWPS110\x1b[0m: Found wrong variable name: handle
Expand Down Expand Up @@ -203,44 +203,44 @@
1:1 WPS111 Found too short name: s < 2
-> https://pyflak.es/WPS111
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
1:7 WPS110 Found wrong variable name: handle
-> https://pyflak.es/WPS110
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
2:21 WPS432 Found magic number: 200
-> https://pyflak.es/WPS432
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
2:21 WPS303 Found underscored number: 2_00
-> https://pyflak.es/WPS303
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
\x1b[4m\x1b[1m./tests/fixtures/formatter/formatter2.py\x1b[0m\x1b[0m
1:1 WPS110 Found wrong variable name: data
-> https://pyflak.es/WPS110
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
1:10 WPS110 Found wrong variable name: param
-> https://pyflak.es/WPS110
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
2:12 WPS437 Found protected attribute usage: _protected
-> https://pyflak.es/WPS437
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
2:31 WPS303 Found underscored number: 10_00
-> https://pyflak.es/WPS303
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
Full list of violations and explanations:
Expand All @@ -251,37 +251,37 @@
\x1b[4m\x1b[1m./tests/fixtures/formatter/formatter1.py\x1b[0m\x1b[0m
1:1 WPS111 Found too short name: s < 2
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
1:7 WPS110 Found wrong variable name: handle
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32ms\x1b[39;49;00m(handle: \x1b[36mint\x1b[39;49;00m) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
2:21 WPS432 Found magic number: 200
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
2:21 WPS303 Found underscored number: 2_00
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m handle + \x1b[34m2_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
\x1b[4m\x1b[1m./tests/fixtures/formatter/formatter2.py\x1b[0m\x1b[0m
1:1 WPS110 Found wrong variable name: data
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
1:10 WPS110 Found wrong variable name: param
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:
\x1b[34mdef\x1b[39;49;00m \x1b[32mdata\x1b[39;49;00m(param) -> \x1b[36mint\x1b[39;49;00m:\x1b[37m\x1b[39;49;00m
^
2:12 WPS437 Found protected attribute usage: _protected
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
2:31 WPS303 Found underscored number: 10_00
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m
\x1b[34mreturn\x1b[39;49;00m param._protected + \x1b[34m10_00\x1b[39;49;00m\x1b[37m\x1b[39;49;00m
^
\x1b[1mWPS110\x1b[0m: Found wrong variable name: handle
Expand Down
Expand Up @@ -33,6 +33,13 @@ def wrapper():
...
"""

context_manager5 = """
def wrapper():
with ({0} if check else nullcontext()) as x:
...
"""


# Wrong:

expression = '{0}'
Expand All @@ -51,6 +58,7 @@ def wrapper():
context_manager2,
context_manager3,
context_manager4,
context_manager5,
])
@pytest.mark.parametrize('call', [
'open()',
Expand Down
12 changes: 11 additions & 1 deletion wemake_python_styleguide/visitors/ast/functions.py
Expand Up @@ -211,10 +211,20 @@ def _check_open_call_context(self, node: ast.Call) -> None:
if not function_name:
return

if isinstance(nodes.get_parent(node), ast.withitem):
parent_node = nodes.get_parent(node)

if isinstance(parent_node, ast.withitem):
# We do not care about `with` or `async with` - both are fine.
return

if_exp_inside_with = (
isinstance(parent_node, ast.IfExp) and
isinstance(nodes.get_parent(parent_node), ast.withitem)
)

if if_exp_inside_with:
return

self.add_violation(OpenWithoutContextManagerViolation(node))

def _check_type_compare(self, node: ast.Call) -> None:
Expand Down

0 comments on commit 4cb5a65

Please sign in to comment.