Skip to content

Commit 9a753da

Browse files
committed
Version 0.6.1, closes #112
1 parent 2162888 commit 9a753da

File tree

14 files changed

+78
-17
lines changed

14 files changed

+78
-17
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ We used to have incremental versioning before `0.1.0`.
1111
- Adds `safety` and other dependency checks to CI process
1212

1313

14+
## Version 0.6.1
15+
16+
### Bugfixes
17+
18+
- Fixes a conflict between our plugin and `pyflakes`
19+
20+
1421
## Version 0.6.0
1522

1623
### Features

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "poetry.masonry.api"
55

66
[tool.poetry]
77
name = "wemake-python-styleguide"
8-
version = "0.6.0"
8+
version = "0.6.1"
99
description = "The strictest and most opinionated python linter ever"
1010

1111
license = "MIT"

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ filterwarnings =
5151
# you an overhead. See `docs/template/development-process.rst`.
5252
addopts =
5353
--doctest-modules
54-
--flake8
5554
--cov=wemake_python_styleguide
5655
--cov-report=term:skip-covered
5756
--cov-report=html
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import ast
4+
5+
from pyflakes.checker import Checker as PyFlakesChecker
6+
7+
from wemake_python_styleguide.checker import Checker
8+
9+
10+
code_that_brakes = '''
11+
def current_session(
12+
telegram_id: int,
13+
for_update: bool = True,
14+
) -> TelegramSession:
15+
"""
16+
Was triggering `AttributeError`.
17+
18+
See: https://github.com/wemake-services/wemake-python-styleguide/issues/112
19+
"""
20+
try:
21+
query = TelegramSession.objects.all()
22+
if for_update: # Try to comment this `if` to fix everything
23+
query = query.select_for_update()
24+
25+
return query.get(
26+
uid=telegram_id,
27+
is_verified=True,
28+
)
29+
30+
except TelegramSession.DoesNotExist:
31+
raise AuthenticationException('Session is missing')
32+
'''
33+
34+
35+
def test_regression112(default_options):
36+
"""
37+
There was a conflict between ``pyflakes`` and our plugin.
38+
39+
We were fighting for ``parent`` property.
40+
Now we use a custom prefix.
41+
42+
See: https://github.com/wemake-services/wemake-python-styleguide/issues/112
43+
"""
44+
module = ast.parse(code_that_brakes)
45+
Checker.parse_options(default_options)
46+
checker = Checker(tree=module, file_tokens=[], filename='custom.py')
47+
48+
# It was failing on this line:
49+
# AttributeError: 'ExceptHandler' object has no attribute 'depth'
50+
flakes = PyFlakesChecker(module)
51+
52+
assert flakes.root

wemake_python_styleguide/transformations/ast/bugfixes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def fix_line_number(tree: ast.AST) -> ast.AST:
5454
for node in ast.walk(tree):
5555
if isinstance(node, affected):
5656
parent_lineno = getattr(
57-
getattr(node, 'parent', None), 'lineno', None,
57+
getattr(node, 'wps_parent', None), 'lineno', None,
5858
)
5959
if parent_lineno and parent_lineno < node.lineno:
6060
node.lineno = node.lineno - 1

wemake_python_styleguide/transformations/ast_tree.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ def _set_parent(tree: ast.AST) -> ast.AST:
2929
This step is required due to how `flake8` works.
3030
It does not set the same properties as `ast` module.
3131
32-
This function was the cause of `issue-112`.
32+
This function was the cause of `issue-112`. Twice.
33+
Since the ``0.6.1`` we use ``'wps_parent'`` with a prefix.
34+
This should fix the issue with conflicting plugins.
3335
3436
.. versionchanged:: 0.0.11
37+
.. versionchanged:: 0.6.1
3538
3639
"""
3740
for statement in ast.walk(tree):
3841
for child in ast.iter_child_nodes(statement):
39-
setattr(child, 'parent', statement)
42+
setattr(child, 'wps_parent', statement)
4043
return tree
4144

4245

wemake_python_styleguide/visitors/ast/builtins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _get_real_parent(self, node: Optional[ast.AST]) -> Optional[ast.AST]:
6565
so ``1`` has ``UnaryOp`` as parent, but should return ``Assign``
6666
6767
"""
68-
parent = getattr(node, 'parent', None)
68+
parent = getattr(node, 'wps_parent', None)
6969
if isinstance(parent, self._proxy_parents):
7070
return self._get_real_parent(parent)
7171
return parent

wemake_python_styleguide/visitors/ast/complexity/counts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self, *args, **kwargs) -> None:
3737

3838
def _check_members_count(self, node: ModuleMembers) -> None:
3939
"""This method increases the number of module members."""
40-
parent = getattr(node, 'parent', None)
40+
parent = getattr(node, 'wps_parent', None)
4141
is_real_method = is_method(getattr(node, 'function_type', None))
4242

4343
if isinstance(parent, ast.Module) and not is_real_method:
@@ -118,7 +118,7 @@ def __init__(self, *args, **kwargs) -> None:
118118
self._methods: DefaultDict[ast.ClassDef, int] = defaultdict(int)
119119

120120
def _check_method(self, node: AnyFunctionDef) -> None:
121-
parent = getattr(node, 'parent', None)
121+
parent = getattr(node, 'wps_parent', None)
122122
if isinstance(parent, ast.ClassDef):
123123
self._methods[parent] += 1
124124

wemake_python_styleguide/visitors/ast/complexity/function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _update_variables(
5757
if variable_def.id == UNUSED_VARIABLE:
5858
return
5959

60-
parent = getattr(variable_def, 'parent', None)
60+
parent = getattr(variable_def, 'wps_parent', None)
6161
if isinstance(parent, self._not_contain_locals):
6262
return
6363

wemake_python_styleguide/visitors/ast/complexity/nested.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ class NestedComplexityVisitor(BaseNodeVisitor):
3737
)
3838

3939
def _check_nested_function(self, node: AnyFunctionDef) -> None:
40-
parent = getattr(node, 'parent', None)
40+
parent = getattr(node, 'wps_parent', None)
4141
is_inside_function = isinstance(parent, self._function_nodes)
4242

4343
if is_inside_function and node.name not in NESTED_FUNCTIONS_WHITELIST:
4444
self.add_violation(NestedFunctionViolation(node, text=node.name))
4545

4646
def _check_nested_classes(self, node: ast.ClassDef) -> None:
47-
parent = getattr(node, 'parent', None)
47+
parent = getattr(node, 'wps_parent', None)
4848
is_inside_class = isinstance(parent, ast.ClassDef)
4949
is_inside_function = isinstance(parent, self._function_nodes)
5050

@@ -54,7 +54,7 @@ def _check_nested_classes(self, node: ast.ClassDef) -> None:
5454
self.add_violation(NestedClassViolation(node, text=node.name))
5555

5656
def _check_nested_lambdas(self, node: ast.Lambda) -> None:
57-
parent = getattr(node, 'parent', None)
57+
parent = getattr(node, 'wps_parent', None)
5858
if isinstance(parent, ast.Lambda):
5959
self.add_violation(NestedFunctionViolation(node))
6060

0 commit comments

Comments
 (0)