Skip to content

Commit

Permalink
WIP: version 0.0.7 release
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Sep 3, 2018
1 parent fadf04a commit 7673dd2
Show file tree
Hide file tree
Showing 29 changed files with 710 additions and 609 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ matrix:
- python: 3.7
dist: xenial
sudo: true
allow_failures:
allow_failures: # we allow failures because of `flake8` warning, it's a bug
- python: 3.7
dist: xenial
sudo: true
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
We follow Semantic Versions.


## Version 0.0.7

### Features

- Added new magic methods to the black list
- We now do not count `_` as a variable in `TooManyLocals` check
- We now restrict to nest `lambda`s
- We now allow to configure the minimal variable's name length via `setup.cfg`

### Misc

- Refactored how complexity checks are defined
- Refactored how errors are defined
- Now each check has strict `Raises:` policy which lists all possible errors
that this check can find and raise


## Version 0.0.6

### Features
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "wemake-python-styleguide"
version = "0.0.6"
version = "0.0.7"
description = "Opinionated styleguide that we use in wemake.services"

license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_visitors/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def assert_errors():
"""Helper function to assert visitor errors."""
def factory(visiter: BaseNodeVisitor, errors: Sequence[str]):
for index, error in enumerate(visiter.errors):
assert len(errors) > index, error._code
assert len(errors) > index, visiter.errors
assert error._code == errors[index]._code

assert len(visiter.errors) == len(errors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

import pytest

from wemake_python_styleguide.visitors.high_complexity import (
ComplexityVisitor,
from wemake_python_styleguide.visitors.complexity.function import (
FunctionComplexityVisitor,
TooManyLocalsViolation,
)

function_with_locals = """
def function():
local_variable1 = 1
local_variable2 = 2
_ = None # `_` is not counted
"""

function_with_locals_redefinition = """
Expand Down Expand Up @@ -45,7 +46,7 @@ def test_locals_correct_count(assert_errors, parse_ast_tree, options, code):
option_values = options(max_local_variables=2)
tree = parse_ast_tree(code)

visiter = ComplexityVisitor()
visiter = FunctionComplexityVisitor()
visiter.provide_options(option_values)
visiter.visit(tree)

Expand All @@ -67,7 +68,7 @@ def test_locals_wrong_count(assert_errors, parse_ast_tree, options, code):
option_values = options(max_local_variables=1)
tree = parse_ast_tree(code)

visiter = ComplexityVisitor()
visiter = FunctionComplexityVisitor()
visiter.provide_options(option_values)
visiter.visit(tree)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import pytest

from wemake_python_styleguide.visitors.wrong_nested import (
from wemake_python_styleguide.visitors.complexity.nested import (
NESTED_CLASSES_WHITELIST,
NestedClassViolation,
WrongNestedVisitor,
NestedComplexityVisitor,
)

nested_class = """
Expand Down Expand Up @@ -34,7 +34,7 @@ def test_nested_class(assert_errors, parse_ast_tree, code):
"""Testing that nested classes are restricted."""
tree = parse_ast_tree(code.format('NestedClass'))

visiter = WrongNestedVisitor()
visiter = NestedComplexityVisitor()
visiter.visit(tree)

assert_errors(visiter, [NestedClassViolation])
Expand All @@ -50,7 +50,7 @@ def test_whitelist_nested_classes(
"""Testing that it is possible to nest whitelisted classes."""
tree = parse_ast_tree(code.format(whitelist_name))

visiter = WrongNestedVisitor()
visiter = NestedComplexityVisitor()
visiter.visit(tree)

assert_errors(visiter, [])
Expand All @@ -70,7 +70,7 @@ def test_whitelist_nested_classes_in_functions(
"""Testing that it is restricted to nest any classes in functions."""
tree = parse_ast_tree(code.format(whitelist_name))

visiter = WrongNestedVisitor()
visiter = NestedComplexityVisitor()
visiter.visit(tree)

assert_errors(visiter, [NestedClassViolation])
Expand All @@ -83,7 +83,7 @@ class Ordinary:
def method(self): ...
""")

visiter = WrongNestedVisitor()
visiter = NestedComplexityVisitor()
visiter.visit(tree)

assert_errors(visiter, [])
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import pytest

from wemake_python_styleguide.visitors.wrong_nested import (
from wemake_python_styleguide.visitors.complexity.nested import (
NESTED_FUNCTIONS_WHITELIST,
NestedComplexityVisitor,
NestedFunctionViolation,
WrongNestedVisitor,
)

nested_function = """
Expand All @@ -28,7 +28,7 @@ def test_nested_function(assert_errors, parse_ast_tree, code):
"""Testing that nested functions are restricted."""
tree = parse_ast_tree(code.format('nested'))

visiter = WrongNestedVisitor()
visiter = NestedComplexityVisitor()
visiter.visit(tree)

assert_errors(visiter, [NestedFunctionViolation])
Expand All @@ -45,7 +45,7 @@ def test_whitelist_nested_functions(
"""Testing that it is possible to nest whitelisted functions."""
tree = parse_ast_tree(code.format(whitelist_name))

visiter = WrongNestedVisitor()
visiter = NestedComplexityVisitor()
visiter.visit(tree)

assert_errors(visiter, [])
Expand All @@ -58,23 +58,27 @@ def container():
lazy_value = lambda: 12
""")

visiter = WrongNestedVisitor()
visiter = NestedComplexityVisitor()
visiter.visit(tree)

assert_errors(visiter, [])


def test_lambda_nested_lambdas(assert_errors, parse_ast_tree):
"""Testing that it is possible to nest lambdas."""
"""
Testing that it is restricted to nest lambdas.
See: https://github.com/wemake-services/wemake-python-styleguide/issues/94
"""
tree = parse_ast_tree("""
def container():
nested_lambda = lambda: lambda value: value + 12
""")

visiter = WrongNestedVisitor()
visiter = NestedComplexityVisitor()
visiter.visit(tree)

assert_errors(visiter, [])
assert_errors(visiter, [NestedFunctionViolation])


def test_lambda_nested_method(assert_errors, parse_ast_tree):
Expand All @@ -85,7 +89,7 @@ def container(self):
lazy_value = lambda: 12
""")

visiter = WrongNestedVisitor()
visiter = NestedComplexityVisitor()
visiter.visit(tree)

assert_errors(visiter, [])
15 changes: 11 additions & 4 deletions wemake_python_styleguide/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
from wemake_python_styleguide.options.config import Configuration
from wemake_python_styleguide.types import CheckResult, ConfigurationOptions
from wemake_python_styleguide.version import version
from wemake_python_styleguide.visitors.high_complexity import ComplexityVisitor
from wemake_python_styleguide.visitors.complexity.function import (
FunctionComplexityVisitor,
)
from wemake_python_styleguide.visitors.complexity.nested import (
NestedComplexityVisitor,
)
from wemake_python_styleguide.visitors.wrong_class import WrongClassVisitor
from wemake_python_styleguide.visitors.wrong_function_call import (
WrongFunctionCallVisitor,
Expand All @@ -21,19 +26,21 @@
WrongModuleMetadataVisitor,
WrongNameVisitor,
)
from wemake_python_styleguide.visitors.wrong_nested import WrongNestedVisitor

#: Visitors that should be working by default:
ENABLED_VISITORS = (
# Styling and correctness:
WrongRaiseVisitor,
WrongFunctionCallVisitor,
WrongImportVisitor,
WrongKeywordVisitor,
WrongNestedVisitor,
ComplexityVisitor,
WrongNameVisitor,
WrongModuleMetadataVisitor,
WrongClassVisitor,

# Complexity:
FunctionComplexityVisitor,
NestedComplexityVisitor,
)


Expand Down
9 changes: 7 additions & 2 deletions wemake_python_styleguide/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

# IO:
'input',
'help',

# Attribute access:
'hasattr',
'delattr',

# Misc:
'copyright',
'help',

# Dynamic imports:
'__import__',
Expand Down Expand Up @@ -83,7 +83,12 @@

#: List of magic methods that are forbiden to use.
BAD_MAGIC_METHODS = frozenset((
'__del__',
'__del__', # since we don't use `del`
'__delitem__', # since we don't use `del`
'__delete__', # since we don't use `del`

'__dir__', # since we don't use `dir()`
'__delattr__', # since we don't use `delattr()`
))

#: List of nested classes' names we allow to use.
Expand Down
Loading

0 comments on commit 7673dd2

Please sign in to comment.