44from textwrap import dedent
55
66import pytest
7- from pep8ext_naming import NamingChecker
87
9-
10- class _ClassVisitor (ast .NodeVisitor ):
11- def __init__ (self , transformer : NamingChecker ) -> None :
12- super ().__init__ ()
13- self .transformer = transformer
14-
15- def visit_ClassDef (self , node : ast .ClassDef ) -> None : # noqa: N802
16- self .transformer .tag_class_functions (node )
17- self .generic_visit (node )
18-
19-
20- def _maybe_set_parent (tree : ast .AST ) -> ast .AST :
21- """
22- Sets parents for all nodes that do not have this prop.
23-
24- This step is required due to how `flake8` works.
25- It does not set the same properties as `ast` module.
26-
27- This function was the cause of `issue-112`.
28-
29- .. versionchanged:: 0.0.11
30-
31- """
32- for statement in ast .walk (tree ):
33- for child in ast .iter_child_nodes (statement ):
34- setattr (child , 'parent' , statement )
35- return tree
36-
37-
38- def _maybe_set_function_type (tree : ast .AST ) -> ast .AST :
39- """
40- Sets the function type for methods.
41-
42- Can set: `method`, `classmethod`, `staticmethod`.
43-
44- .. versionchanged:: 0.3.0
45-
46- """
47- transformer = _ClassVisitor (NamingChecker (tree , 'stdin' ))
48- transformer .visit (tree )
49- return tree
8+ from wemake_python_styleguide .transformation .ast_tree import transform
509
5110
5211@pytest .fixture (scope = 'session' )
@@ -65,11 +24,6 @@ def parse_ast_tree():
6524
6625 Order is important.
6726 """
68- transformation_pipeline = [
69- _maybe_set_parent ,
70- _maybe_set_function_type ,
71- ]
72-
7327 def factory (code : str , do_compile : bool = True ) -> ast .AST :
7428 code_to_parse = dedent (code )
7529
@@ -78,10 +32,6 @@ def factory(code: str, do_compile: bool = True) -> ast.AST:
7832 # that are validated after the `ast` is processed:
7933 # like double arguments or `break` outside of loops.
8034 compile (code_to_parse , '<filename>' , 'exec' ) # noqa: Z421
81- tree = ast .parse (code_to_parse )
82-
83- for transform in transformation_pipeline :
84- tree = transform (tree )
85- return tree
35+ return transform (ast .parse (code_to_parse ))
8636
8737 return factory
0 commit comments