Skip to content

Commit

Permalink
Version 0.9.0 pre-release
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Jun 20, 2019
1 parent cf33aa3 commit c012c72
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 49 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ and lots of bug fixes.
- Fixes false positive for compare ordering with `await`
- Fixes problem with missing `_allowed_left_nodes`
- Fixes problem false positive for `Z121` when using `_` for unused var names
- Fixes false positive for negative number in default values
- Fixes error text for `ComplexDefaultValuesViolation`
- Fixes problem with false positive for `Z459`
when a default value is an `Ellipsis`

Expand All @@ -35,6 +37,7 @@ and lots of bug fixes.
- Adds big "Star" button
- Multiple dependencies update
- Better `exclude` rule for `flake8` check
- Removed warnings from `pytest`


## 0.8.1
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 @@ -72,4 +72,4 @@ def factory(template: str) -> str:
@pytest.fixture(params=['async_wrapper', 'regular_wrapper'])
def mode(request):
"""Fixture that returns either `async` or regular functions."""
return request.getfuncargvalue(request.param)
return request.getfixturevalue(request.param)
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,17 @@
FunctionDefinitionVisitor,
)

function_with_ellipse_default = """
def __init__(self, inner_value: None = ...) -> None:
...
"""


function_with_defaults = """
def __init__(
self,
tree,
filename='(none)',
builtins=None,
withDoctest={0},
tokens=(),
):
pass
def function(self, with_default={0}):
...
"""

bad_default = "'PYFLAKES_DOCTEST' in os.environ"
good_default = 'SHOULD_USE_DOCTEST'


@pytest.mark.parametrize('code', [
function_with_defaults,
bad_default,
"'PYFLAKES_DOCTEST' in os.environ",
'call()',
'index[1]',
'compare == 1',
])
def test_wrong_function_defaults(
assert_errors,
Expand All @@ -44,7 +30,7 @@ def test_wrong_function_defaults(
mode,
):
"""Testing that wrong function defaults are forbidden."""
tree = parse_ast_tree(function_with_defaults.format(bad_default))
tree = parse_ast_tree(function_with_defaults.format(code))

visitor = FunctionDefinitionVisitor(default_options, tree=tree)
visitor.run()
Expand All @@ -53,8 +39,14 @@ def test_wrong_function_defaults(


@pytest.mark.parametrize('code', [
function_with_defaults,
good_default,
"'string'",
"b''",
'1',
'-0',
'variable',
'(1, 2)',
'None',
'...',
])
def test_correct_function_defaults(
assert_errors,
Expand All @@ -65,23 +57,7 @@ def test_correct_function_defaults(
mode,
):
"""Testing that correct function defaults passes validation."""
tree = parse_ast_tree(mode(function_with_defaults.format(good_default)))

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

assert_errors(visitor, [])


def test_ellipse_correct_default(
assert_errors,
assert_error_text,
parse_ast_tree,
default_options,
mode,
):
"""Testing that ellipse is accepted as a correct default value."""
tree = parse_ast_tree(mode(function_with_ellipse_default))
tree = parse_ast_tree(mode(function_with_defaults.format(code)))

visitor = FunctionDefinitionVisitor(default_options, tree=tree)
visitor.run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def container():
"""


# We ignore `DeprecationWarning: 'yield' inside generator expression` here
@pytest.mark.filterwarnings('ignore:DeprecationWarning')
@pytest.mark.parametrize('code', [
list_comprehension,
generator_expression,
Expand Down
4 changes: 2 additions & 2 deletions wemake_python_styleguide/violations/best_practices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1638,10 +1638,10 @@ class ComplexDefaultValuesViolation(ASTViolation):
# Correct:
SHOULD_USE_DOCTEST = 'PYFLAKES_DOCTEST' in os.environ
def __init__(self, withDoctest=SHOULD_USE_DOCTEST):
def __init__(self, with_doctest=SHOULD_USE_DOCTEST):
# Wrong:
def __init__(self, withDoctest='PYFLAKES_DOCTEST' in os.environ):
def __init__(self, with_doctest='PYFLAKES_DOCTEST' in os.environ):
.. versionadded:: 0.8.0
Expand Down
10 changes: 4 additions & 6 deletions wemake_python_styleguide/visitors/ast/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
FUNCTIONS_BLACKLIST,
UNUSED_VARIABLE,
)
from wemake_python_styleguide.logics import functions
from wemake_python_styleguide.logics import functions, operators
from wemake_python_styleguide.logics.naming import access
from wemake_python_styleguide.types import AnyFunctionDef, AnyNodes
from wemake_python_styleguide.violations.best_practices import (
Expand Down Expand Up @@ -167,12 +167,10 @@ def _check_unused_variables(self, node: AnyFunctionDef) -> None:
self._check_used_variables(local_variables)

def _check_argument_default_values(self, node: AnyFunctionDef) -> None:

for arg in node.args.defaults:
if not isinstance(arg, self._allowed_default_value_types):
self.add_violation(
ComplexDefaultValuesViolation(node, text='Test text'),
)
real_arg = operators.unwrap_unary_node(arg)
if not isinstance(real_arg, self._allowed_default_value_types):
self.add_violation(ComplexDefaultValuesViolation(node))

def visit_any_function(self, node: AnyFunctionDef) -> None:
"""
Expand Down

0 comments on commit c012c72

Please sign in to comment.