Skip to content

Commit

Permalink
Closes #1170
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Feb 19, 2020
1 parent 24a3780 commit 4dea0fd
Show file tree
Hide file tree
Showing 19 changed files with 334 additions and 53 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Expand Up @@ -14,6 +14,8 @@ Semantic versioning in our case means:
### Features

- **Breaking**: removes `flake8-print`, now using `WPS421` instead of `T001`
- **Breaking**: removes `flake8-annotations-complexity`,
now using `WPS234` instead of `TAE002`
- Adds `python3.8` support
- Removes `radon`, because `cognitive-complexity` is enough
- Removes `flake8-loggin-format` as a direct dependency
Expand All @@ -22,7 +24,9 @@ Semantic versioning in our case means:
- Adds support for positional arguments in different checks
- Changes `styleguide.toml` and `flake8.toml` scripts definition
- Extracts new violation - WPS450 from WPS436 #1118
- Adds domain names options, that are used to create variable names' blacklist #1106
- Adds domain names options:
`--allowed-domain-names` and `--forbidden-domain-names`,
that are used to create variable names' blacklist #1106
- Forbids to use `:=` operator
- Forbids to use positional only `/` arguments
- Adds `__call__` to list of methods that should be on top #1125
Expand All @@ -34,6 +38,8 @@ Semantic versioning in our case means:
- Fixes that cognitive complexity was ignoring
`ast.Continue`, `ast.Break`, and `ast.Raise` statements
- Fixes that cognitive complexity was ignoring `ast.AsyncFor` loops
- Fixes that annotation complexity was not reported for `async` functions
- Fixes that annotation complexity was not reported from lists

### Misc

Expand Down
1 change: 0 additions & 1 deletion docs/pages/usage/violations/index.rst
Expand Up @@ -46,7 +46,6 @@ flake8-quotes `Q000 <https://github.com/zheller/flake8-quotes>`
flake8-pep3101 `S001 <https://github.com/gforcada/flake8-pep3101/blob/master/flake8_pep3101.py>`_
flake8-bandit `S100 - S710 <https://github.com/tylerwince/flake8-bandit>`_, see also original ``bandit`` `codes <https://bandit.readthedocs.io/en/latest/plugins/index.html#complete-test-plugin-listing>`_
flake8-debugger `T100 <https://github.com/JBKahn/flake8-debugger/blob/master/flake8_debugger.py>`_
flake8-annotations-complexity `TAE002 <https://github.com/best-doctor/flake8-annotations-complexity>`_
flake8-rst-docstrings `RST201 - RST499 <https://github.com/peterjc/flake8-rst-docstrings>`_
flake8-executable `EXE001 - EXE005 <https://github.com/xuhdev/flake8-executable>`_
darglint `DAR001 - DAR501 <https://github.com/terrencepreilly/darglint#error-codes>`_
Expand Down
42 changes: 14 additions & 28 deletions poetry.lock

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

1 change: 0 additions & 1 deletion pyproject.toml
Expand Up @@ -73,7 +73,6 @@ flake8-isort = "^2.6"
flake8-eradicate = "^0.2"
flake8-bandit = "^2.1"
flake8-broken-line = "^0.1"
flake8-annotations-complexity = "^0.0.2"
flake8-rst-docstrings = "^0.0.12"
flake8-executable = "^2.0"
pep8-naming = "^0.9.1"
Expand Down
6 changes: 0 additions & 6 deletions tests/fixtures/external_plugins.py
Expand Up @@ -33,12 +33,6 @@ def function_name(plugin: str ='flake8') ->str:
'\''


def complex_annotation(
first: List[Union[List[str], Dict[str, Dict[str, str]]]],
):
...


def darglint_check(arg):
"""
Used to trigger DAR101.
Expand Down
5 changes: 4 additions & 1 deletion tests/fixtures/noqa/noqa.py
Expand Up @@ -7,6 +7,8 @@

from __future__ import print_function # noqa: WPS422

from typing import List

import os.path # noqa: WPS301
import sys as sys # noqa: WPS113

Expand All @@ -19,7 +21,6 @@
import import2
import import3
import import4
import import5

from some_name import (
name1,
Expand Down Expand Up @@ -684,6 +685,8 @@ def consecutive_yields():

deep_func(a)(b)(c)(d) # noqa: WPS233

annotated: List[List[List[List[int]]]] # noqa: WPS234

extra_new_line = [ # noqa: WPS355

'wrong',
Expand Down
1 change: 1 addition & 0 deletions tests/test_checker/test_noqa.py
Expand Up @@ -103,6 +103,7 @@
'WPS231': 1,
'WPS232': 0, # logically unacceptable.
'WPS233': 1,
'WPS234': 1,

'WPS300': 1,
'WPS301': 1,
Expand Down
1 change: 0 additions & 1 deletion tests/test_plugins.py
Expand Up @@ -31,7 +31,6 @@
'S001', # flake8-pep3101
'S101', # flake8-bandit
'T100', # flake8-debugger
'TAE002', # flake8-annotations-complexity
'RST215', # flake8-rst-docstrings
'EXE003', # flake8-executable
'DAR101', # darglint
Expand Down
@@ -0,0 +1,125 @@
# -*- coding: utf-8 -*-

import pytest

from wemake_python_styleguide.violations.complexity import (
TooComplexAnnotationViolation,
)
from wemake_python_styleguide.visitors.ast.complexity.annotations import (
AnnotationComplexityVisitor,
)

annassign_template = 'some: {0}'

function_arg_template = """
def some(arg: {0}):
...
"""

function_return_template = """
def some(arg) -> {0}:
...
"""

class_field_template = """
class Test(object):
some: {0}
other = 1
"""


@pytest.mark.parametrize('template', [
annassign_template,
function_arg_template,
function_return_template,
class_field_template,
])
@pytest.mark.parametrize('code', [
'int',
'List[int]',
'List["MyType"]',
'"List[MyType]"',
'Dict[int, str]',
'Callable[[str, int], int]',
'List[List[int]]',
])
def test_correct_annotations(
assert_errors,
parse_ast_tree,
template,
code,
mode,
default_options,
):
"""Testing that expressions with correct call chain length work well."""
tree = parse_ast_tree(mode(template.format(code)))

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

assert_errors(visitor, [])


@pytest.mark.parametrize('template', [
annassign_template,
function_arg_template,
function_return_template,
class_field_template,
])
@pytest.mark.parametrize('code', [
'List[List[List[int]]]',
'"List[List[List[int]]]"',
'Callable[[], "List[List[str]]"]',
'Callable[[List["List[str]"]], str]',
'Dict[int, Tuple[List[List[str]], ...]]',
'"Dict[int, Tuple[List[List[str]], ...]]"',
'Dict[int, "Tuple[List[List[str]], ...]"]',
'Dict[int, Tuple["List[List[str]]", ...]]',
'Dict[int, Tuple[List["List[str]"], ...]]',
])
def test_complex_annotations(
assert_errors,
parse_ast_tree,
template,
code,
mode,
default_options,
):
"""Testing that expressions with correct call chain length work well."""
tree = parse_ast_tree(mode(template.format(code)))

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

assert_errors(visitor, [TooComplexAnnotationViolation])


@pytest.mark.parametrize('template', [
annassign_template,
function_arg_template,
function_return_template,
class_field_template,
])
@pytest.mark.parametrize('code', [
'List[List[int]]',
'"List[List[int]]"',
'List["List[int]"]',
])
def test_complex_annotations_config(
assert_errors,
parse_ast_tree,
template,
code,
mode,
options,
):
"""Testing that expressions with correct call chain length work well."""
tree = parse_ast_tree(mode(template.format(code)))

option_values = options(max_annotation_complexity=2)
visitor = AnnotationComplexityVisitor(option_values, tree=tree)
visitor.run()

assert_errors(visitor, [TooComplexAnnotationViolation])
Expand Up @@ -63,10 +63,11 @@ def test_not_posonlyargs(
assert_errors,
parse_ast_tree,
code,
mode,
default_options,
):
"""Testing that regular code is allowed."""
tree = parse_ast_tree(code)
tree = parse_ast_tree(mode(code))

visitor = PositionalOnlyArgumentsVisitor(default_options, tree=tree)
visitor.run()
Expand All @@ -88,10 +89,11 @@ def test_posonyargs(
assert_errors,
parse_ast_tree,
code,
mode,
default_options,
):
"""Testing that ``/`` is not allowed."""
tree = parse_ast_tree(code)
tree = parse_ast_tree(mode(code))

visitor = PositionalOnlyArgumentsVisitor(default_options, tree=tree)
visitor.run()
Expand Down

0 comments on commit 4dea0fd

Please sign in to comment.