Skip to content

Commit

Permalink
Version 0.7.1, closes #459, closes #476
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Feb 8, 2019
1 parent 0c0b669 commit a9f6a0b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 26 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ We follow Semantic Versions since the `0.1.0` release.
We used to have incremental versioning before `0.1.0`.


## 0.7.1

### Bugfixes

- Allows `Generic[SomeType]` to be a valid superclass
- Forces to use `flake8` version `3.6` instead of `3.7`

### Misc

- Improves docs about using `# type: some` comment in `for` loops


## 0.7.0

### Features
Expand Down
36 changes: 18 additions & 18 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions 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.7.0"
version = "0.7.1"
description = "The strictest and most opinionated python linter ever"

license = "MIT"
Expand Down Expand Up @@ -42,8 +42,8 @@ classifiers = [
Z = "wemake_python_styleguide.checker:Checker"

[tool.poetry.dependencies]
python = "^3.6 || ^3.7"
flake8 = "^3.6"
python = "^3.6"
flake8 = "~3.6"
attrs = "^18.2"
typing_extensions = "^3.6"
astor = "^0.7.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Meta({0}):
])
@pytest.mark.parametrize('base', [
'(lambda: object)()',
'some_dict["key"]',
'method.call()',
'-Name',
'[1, 2, 3]',
Expand Down Expand Up @@ -48,6 +47,13 @@ def test_base_class_expression(
'Deep.Nested.Attr',
'One, Two',
'One, keyword=None',
# Regressions
# See: issue-459
'Generic[ValueType]',
'Monad[ValueType, ErrorType]',
'Generic[Some], metaclass=abc.ABCMeta',
'Generic["TextType"]',
])
def test_correct_base_classes(
assert_errors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Meta:
"""

class_with_empty_base = """
class Meta():
'''Docs.'''
class Meta():
'''Docs.'''
"""

nested_class_without_base = """
Expand Down
8 changes: 7 additions & 1 deletion wemake_python_styleguide/violations/best_practices.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ class WrongMagicCommentViolation(SimpleViolation):
coordinate: int = 10
some.int_field = 'text' # type: ignore
number: int
for number in some_untyped_iterable():
...
# Wrong:
type = MyClass.get_type() # noqa
coordinate = 10 # type: int
Expand Down Expand Up @@ -1365,17 +1369,19 @@ class IncorrectBaseClassViolation(ASTViolation):
We need to prevent dirty hacks in this field.
Solution:
Use only raw names to set your base classes.
Use only attributes, names, and types to be your base classes.
Example::
# Correct:
class Test(module.ObjectName, MixinName, keyword=True): ...
class GenericClass(Generic[ValueType]): ...
# Wrong:
class Test((lambda: object)()): ...
.. versionadded:: 0.7.0
.. versionchanged:: 0.7.1
"""

Expand Down
8 changes: 7 additions & 1 deletion wemake_python_styleguide/visitors/ast/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ class WrongClassVisitor(BaseNodeVisitor):
ast.AnnAssign, # type annotations
)

_allowed_base_classes_nodes: ClassVar[types.AnyNodes] = (
ast.Name,
ast.Attribute,
ast.Subscript,
)

def _check_base_classes(self, node: ast.ClassDef) -> None:
if len(node.bases) == 0:
self.add_violation(
RequiredBaseClassViolation(node, text=node.name),
)

for base_name in node.bases:
if not isinstance(base_name, (ast.Name, ast.Attribute)):
if not isinstance(base_name, self._allowed_base_classes_nodes):
self.add_violation(IncorrectBaseClassViolation(node))
continue

Expand Down

0 comments on commit a9f6a0b

Please sign in to comment.