From 300f257e8f2ba09e54d15c117da164f612a54346 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sat, 5 Jan 2019 18:47:49 +0300 Subject: [PATCH] Version 0.6.2 --- CHANGELOG.md | 7 +++++ pyproject.toml | 2 +- .../test_naming/test_class_attributes.py | 26 +++++++++++++++++++ .../visitors/ast/naming.py | 9 ++++--- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9faa9a29d..2cfa03687 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 960b59699..f71124e79 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/tests/test_visitors/test_ast/test_naming/test_class_attributes.py b/tests/test_visitors/test_ast/test_naming/test_class_attributes.py index 642f4a86e..91bdb8bdc 100644 --- a/tests/test_visitors/test_ast/test_naming/test_class_attributes.py +++ b/tests/test_visitors/test_ast/test_naming/test_class_attributes.py @@ -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', @@ -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, []) diff --git a/wemake_python_styleguide/visitors/ast/naming.py b/wemake_python_styleguide/visitors/ast/naming.py index 90313f961..4c313e49c 100644 --- a/wemake_python_styleguide/visitors/ast/naming.py +++ b/wemake_python_styleguide/visitors/ast/naming.py @@ -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, @@ -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), )