Skip to content

Commit

Permalink
Change rule behaviour: support only 3.13+ typevars. Change tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapeline committed Feb 27, 2025
1 parent 41c7e05 commit b31d45a
Show file tree
Hide file tree
Showing 26 changed files with 459 additions and 368 deletions.
539 changes: 321 additions & 218 deletions poetry.lock

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions tests/fixtures/noqa/noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,17 +747,3 @@ def my_function():

def pos_only_problem(first_argpm=0, second_argpm=1, /): # noqa: WPS475
my_print(first_argpm, second_argpm)


TypeVarDefault = TypeVar("T", default=int)
FollowingTuple = TypeVarTuple("Ts")


class NewStyleGenerics[TypeVarDefault, *FollowingTuple]: # noqa: WPS476
...


class OldStyleGenerics(
Generic[TypeVarDefault, *FollowingTuple] # noqa: WPS476
):
...
11 changes: 11 additions & 0 deletions tests/fixtures/noqa/noqa313.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
This file contains all possible violations for python 3.13+.
It is used for e2e tests.
"""

class NewStyleGenerics[
TypeVarDefault=int,
*FollowingTuple=*tuple[int, ...] # noqa: WPS476
]:
"""TypeVarTuple follows a defaulted TypeVar."""
40 changes: 35 additions & 5 deletions tests/test_checker/test_noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
'WPS402', # we obviously use a lot of `noqa` comments
)

#: List of ignored violations on python 3.13+.
IGNORED_VIOLATIONS3_13 = (

)

#: Number and count of violations that would be raised.
SHOULD_BE_RAISED = types.MappingProxyType(
{
Expand Down Expand Up @@ -234,6 +239,7 @@
'WPS473': 0,
'WPS474': 1,
'WPS475': 1,
'WPS476': 0, # enabled only in python 3.13+
'WPS500': 1,
'WPS501': 1,
'WPS502': 0, # disabled since 1.0.0
Expand Down Expand Up @@ -292,6 +298,13 @@
},
)

#: Number and count of violations that would be raised in 3.13+ section.
SHOULD_BE_RAISED3_13 = types.MappingProxyType(
dict.fromkeys(SHOULD_BE_RAISED, 0) | {
'WPS476': 1
}
)


def _assert_errors_count_in_output(
output,
Expand Down Expand Up @@ -324,6 +337,7 @@ def test_codes(all_violations):
('filename', 'violations'),
[
('noqa.py', SHOULD_BE_RAISED),
('noqa313.py', SHOULD_BE_RAISED3_13),
],
)
def test_noqa_fixture_disabled(
Expand Down Expand Up @@ -360,7 +374,14 @@ def test_noqa_fixture_disabled(
)


def test_noqa_fixture(absolute_path):
@pytest.mark.parametrize(
'filename',
[
'noqa.py',
'noqa313.py',
]
)
def test_noqa_fixture(absolute_path, filename):
"""End-to-End test to check that `noqa` works."""
process = subprocess.Popen(
[
Expand All @@ -370,7 +391,7 @@ def test_noqa_fixture(absolute_path):
'--isolated',
'--select',
'WPS, E999',
absolute_path('fixtures', 'noqa', 'noqa.py'),
absolute_path('fixtures', 'noqa', filename),
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand All @@ -383,15 +404,24 @@ def test_noqa_fixture(absolute_path):
assert not stderr.count('WPS')


def test_noqa_fixture_without_ignore(absolute_path):
@pytest.mark.parametrize(
('filename', 'ignored_violations'),
[
('noqa.py', IGNORED_VIOLATIONS),
('noqa313.py', IGNORED_VIOLATIONS3_13),
]
)
def test_noqa_fixture_without_ignore(
absolute_path, filename, ignored_violations
):
"""End-to-End test to check that `noqa` works without ignores."""
process = subprocess.Popen(
[
'flake8',
'--isolated',
'--select',
'WPS, E999',
absolute_path('fixtures', 'noqa', 'noqa.py'),
absolute_path('fixtures', 'noqa', filename),
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
Expand All @@ -400,5 +430,5 @@ def test_noqa_fixture_without_ignore(absolute_path):
)
stdout, _ = process.communicate()

for violation in IGNORED_VIOLATIONS:
for violation in ignored_violations:
assert stdout.count(violation) > 0
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest

from wemake_python_styleguide.violations.oop import BuiltinSubclassViolation
from wemake_python_styleguide.visitors.ast.classes import WrongClassDefVisitor
from wemake_python_styleguide.visitors.ast.classes.classdef import (
WrongClassDefVisitor,
)

class_with_base = 'class TestClass({0}): ...'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from wemake_python_styleguide.violations.best_practices import (
BaseExceptionSubclassViolation,
)
from wemake_python_styleguide.visitors.ast.classes import WrongClassDefVisitor
from wemake_python_styleguide.visitors.ast.classes.classdef import (
WrongClassDefVisitor,
)

class_with_base = """
class Meta({0}):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from wemake_python_styleguide.violations.best_practices import (
KwargsUnpackingInClassDefinitionViolation,
)
from wemake_python_styleguide.visitors.ast.classes import WrongClassDefVisitor
from wemake_python_styleguide.visitors.ast.classes.classdef import (
WrongClassDefVisitor,
)

# Wrong:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest

from wemake_python_styleguide.violations.oop import WrongBaseClassViolation
from wemake_python_styleguide.visitors.ast.classes import WrongClassDefVisitor
from wemake_python_styleguide.visitors.ast.classes.classdef import (
WrongClassDefVisitor,
)

class_with_base = """
class Meta({0}):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest

from wemake_python_styleguide.violations.oop import BuggySuperContextViolation
from wemake_python_styleguide.visitors.ast.classes import BuggySuperCallVisitor
from wemake_python_styleguide.visitors.ast.classes.methods import (
BuggySuperCallVisitor,
)

error_dict_comprehension = """
{super().make_key(it): make_value(it) for it in items}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from wemake_python_styleguide.violations.oop import (
ShadowedClassAttributeViolation,
)
from wemake_python_styleguide.visitors.ast.classes import ClassAttributeVisitor
from wemake_python_styleguide.visitors.ast.classes.attributes import (
ClassAttributeVisitor,
)

# Can raise:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest

from wemake_python_styleguide.violations.oop import WrongSlotsViolation
from wemake_python_styleguide.visitors.ast.classes import WrongSlotsVisitor
from wemake_python_styleguide.visitors.ast.classes.attributes import (
WrongSlotsVisitor,
)

class_body_template = """
class ClassWithSlots:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from wemake_python_styleguide.violations.oop import (
UnpythonicGetterSetterViolation,
)
from wemake_python_styleguide.visitors.ast.classes import WrongClassBodyVisitor
from wemake_python_styleguide.visitors.ast.classes.classdef import (
WrongClassBodyVisitor,
)

module_getter_and_setter = """
attribute = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from wemake_python_styleguide.violations.oop import (
LambdaAttributeAssignedViolation,
)
from wemake_python_styleguide.visitors.ast.classes import ClassAttributeVisitor
from wemake_python_styleguide.visitors.ast.classes.attributes import (
ClassAttributeVisitor,
)

# Correct:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from wemake_python_styleguide.violations.consistency import (
WrongMethodOrderViolation,
)
from wemake_python_styleguide.visitors.ast.classes import (
from wemake_python_styleguide.visitors.ast.classes.methods import (
ClassMethodOrderVisitor,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest

from wemake_python_styleguide.violations.oop import AsyncMagicMethodViolation
from wemake_python_styleguide.visitors.ast.classes import WrongMethodVisitor
from wemake_python_styleguide.visitors.ast.classes.methods import (
WrongMethodVisitor,
)

sync_method = """
class Example:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest

from wemake_python_styleguide.violations.oop import AsyncMagicMethodViolation
from wemake_python_styleguide.visitors.ast.classes import WrongMethodVisitor
from wemake_python_styleguide.visitors.ast.classes.methods import (
WrongMethodVisitor,
)

sync_method = """
class Example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from wemake_python_styleguide.constants import MAGIC_METHODS_BLACKLIST
from wemake_python_styleguide.violations.oop import BadMagicMethodViolation
from wemake_python_styleguide.visitors.ast.classes import WrongMethodVisitor
from wemake_python_styleguide.visitors.ast.classes.methods import (
WrongMethodVisitor,
)

magic_method = """
class Example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
MethodWithoutArgumentsViolation,
StaticMethodViolation,
)
from wemake_python_styleguide.visitors.ast.classes import WrongMethodVisitor
from wemake_python_styleguide.visitors.ast.classes.methods import (
WrongMethodVisitor,
)

method_inside_class = """
class Example:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest

from wemake_python_styleguide.violations.oop import StaticMethodViolation
from wemake_python_styleguide.visitors.ast.classes import WrongMethodVisitor
from wemake_python_styleguide.visitors.ast.classes.methods import (
WrongMethodVisitor,
)

decorated_method = """
class Example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import pytest

from wemake_python_styleguide.violations import oop
from wemake_python_styleguide.visitors.ast.classes import WrongMethodVisitor
from wemake_python_styleguide.visitors.ast.classes.methods import (
WrongMethodVisitor,
)

regular_method_detailed = """
class Useless:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest

from wemake_python_styleguide.violations.oop import YieldMagicMethodViolation
from wemake_python_styleguide.visitors.ast.classes import WrongMethodVisitor
from wemake_python_styleguide.visitors.ast.classes.methods import (
WrongMethodVisitor,
)

method_template = """
class Test:
Expand Down
Loading

0 comments on commit b31d45a

Please sign in to comment.