Skip to content

Commit

Permalink
revert: Annotations semantic checks
Browse files Browse the repository at this point in the history
Why? Because it is too complex and bring a very little value.

Let me explain. Annotations can be used in multiple ways:

1. As Python structures: `List[int]`
2. As strings: `'SelfType[T]'`
3. As a mix of these two: `List['SelfType[T]']`

It is also really hard to tell that annotations are really the same.
Because, here's how one can write `Literal` (as an example):

1. `Literal[1]`
2. `typing.Literal[1]`
3. `t.Literal[1]`
4. `te.Literal[1]`
5. `typing_extensions.Literal[1]`
6. `'Literal[1]'`
7. ...

It would be the same annotation in all these cases. But different `ast` nodes.
Comparing them is hard. And error-prone.

We also break one very important princible of our project: we assume types.
That's why it is reverted.
  • Loading branch information
sobolevn committed Nov 7, 2019
1 parent 059e58b commit 02a934c
Show file tree
Hide file tree
Showing 16 changed files with 5 additions and 536 deletions.
3 changes: 2 additions & 1 deletion .importlinter
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ modules =
wemake_python_styleguide.violations.best_practices
wemake_python_styleguide.violations.refactoring
wemake_python_styleguide.violations.oop
wemake_python_styleguide.violations.annotations


[importlinter:contract:flake8-independence]
Expand Down Expand Up @@ -68,6 +67,8 @@ forbidden_modules =
radon
astor
cognitive_complexity
astboom
tokelor

ignore_imports =
# These modules must import from flake8 to provide required API:
Expand Down
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ We used to have incremental versioning before `0.1.0`.
- Forbids to use implicit primitive values in a form of `lambda: 0`
- Forbids to use approximate math constants
- Forbids to redefine string constants
- Forbids using `Literal[None]` in function annotations
- Forbids using nested `typing.Literal`, `typing.Union` and `typing.Annotated`
- Forbids use of vague import names (e.g. `from json import loads`)
- Makes `OveruseOfNoqaCommentViolation` configurable via `--max-noqa-comments`
- Forbid incorrectly swapped variables
- Forbids to use redundant subscripts (e.g., `[0:7]` or `[3:None]`)
- Allows `super()` as a valid overused expression
- Forbids to use `super()` with other methods and properties
- `WPS350` enforces using augmented assign pattern
- Forbids to use `Optional[Union[...]]` in annotations
- Forbids unnecessary literals
- `WPS525` forbids comparisons where `in` is compared with single item container
- Forbids wrong annotations in assignment
Expand Down
7 changes: 0 additions & 7 deletions docs/pages/usage/violations/annotations.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/pages/usage/violations/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ wemake-python-styleguide WPS, defined here
best_practices.rst
refactoring.rst
oop.rst
annotations.rst
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from wemake_python_styleguide.options.config import Configuration

pytest_plugins = ['violation_fixtures']
pytest_plugins = ['plugins.violations']


@pytest.fixture(scope='session')
Expand Down
4 changes: 0 additions & 4 deletions tests/fixtures/noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,6 @@ async def async_gen(self):
assert [] # noqa: WPS444
unhashable = [] * 2 # noqa: WPS435

type1: Literal[None] # noqa: WPS700
type2: Union[str, Union[int, float]] # noqa: WPS701
arg: Optional[Union[str, int]] # noqa: WPS702

from json import loads # noqa: WPS347

some_model = (
Expand Down
2 changes: 0 additions & 2 deletions tests/violation_fixtures.py → tests/plugins/violations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pytest

from wemake_python_styleguide.violations import (
annotations,
best_practices,
complexity,
consistency,
Expand Down Expand Up @@ -47,7 +46,6 @@ def _load_all_violation_classes():
best_practices,
refactoring,
oop,
annotations,
]

classes = {}
Expand Down
4 changes: 0 additions & 4 deletions tests/test_checker/test_noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@
'WPS611': 1,
'WPS612': 1,
'WPS613': 1,

'WPS700': 1,
'WPS701': 1,
'WPS702': 1,
})

# Violations which may be tweaked by `i_control_code` option
Expand Down
2 changes: 1 addition & 1 deletion tests/test_checker/test_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _is_visitor_class(cls) -> bool:
BaseTokenVisitor,
BaseVisitor,
}
if not inspect.isclass(cls) or cls.__qualname__.startswith('_'):
if not inspect.isclass(cls):
return False

return issubclass(cls, BaseVisitor) and cls not in base_classes
Expand Down
2 changes: 1 addition & 1 deletion tests/test_violations/test_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_all_unique_violation_codes(all_violations):

def test_all_violations_correct_numbers(all_module_violations):
"""Ensures that all violations has correct violation code numbers."""
assert len(all_module_violations) == 8
assert len(all_module_violations) == 7

for index, module in enumerate(all_module_violations.keys()):
code_number = index * 100
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion wemake_python_styleguide/presets/types/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@

attributes.WrongAttributeVisitor,
annotations.WrongAnnotationVisitor,
annotations.SemanticAnnotationVisitor,

functions.WrongFunctionCallVisitor,
functions.FunctionDefinitionVisitor,
Expand Down
Loading

0 comments on commit 02a934c

Please sign in to comment.