Skip to content

Commit

Permalink
Version 0.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Jan 5, 2019
1 parent 9a753da commit 300f257
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ We used to have incremental versioning before `0.1.0`.
- Adds `safety` and other dependency checks to CI process


## Version 0.6.2

### Bugfixes

- Fixes a [crash](https://github.com/wemake-services/wemake-python-styleguide/issues/423) with class attributes assignment


## Version 0.6.1

### Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "poetry.masonry.api"

[tool.poetry]
name = "wemake-python-styleguide"
version = "0.6.1"
version = "0.6.2"
description = "The strictest and most opinionated python linter ever"

license = "MIT"
Expand Down
26 changes: 26 additions & 0 deletions tests/test_visitors/test_ast/test_naming/test_class_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ class Test(object):
{0} = None
"""

regression423 = """
class MyClass(object):
def action_method(self, request, object):
...
action_method.label = 'Do action'
"""


@pytest.mark.parametrize('non_snake_case_name', [
'Abc',
Expand Down Expand Up @@ -60,3 +68,21 @@ def test_snake_case_class_attributes(
visitor.run()

assert_errors(visitor, [])


def test_regression423(
assert_errors,
parse_ast_tree,
default_options,
):
"""
Tests that this issue-423 won't happen again.
See: https://github.com/wemake-services/wemake-python-styleguide/issues/423
"""
tree = parse_ast_tree(regression423)

visitor = WrongNameVisitor(default_options, tree=tree)
visitor.run()

assert_errors(visitor, [])
9 changes: 6 additions & 3 deletions wemake_python_styleguide/visitors/ast/naming.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

import ast
from typing import Callable, List, Tuple, Union
from typing import Callable, List, Optional, Tuple, Union

from wemake_python_styleguide.constants import (
MODULE_METADATA_VARIABLES_BLACKLIST,
Expand Down Expand Up @@ -113,8 +113,11 @@ def check_attribute_name(self, node: ast.ClassDef) -> None:

for assignment in top_level_assigns:
for target in assignment.targets:
name = getattr(target, 'id', None)
if logical.is_upper_case_name(name):
if not isinstance(target, ast.Name):
continue

name: Optional[str] = getattr(target, 'id', None)
if name and logical.is_upper_case_name(name):
self._error_callback(
naming.UpperCaseAttributeViolation(target, text=name),
)
Expand Down

0 comments on commit 300f257

Please sign in to comment.