We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Feature: count async methods as methods inside classes
Here we count how many methods the class has: https://github.com/wemake-services/wemake-python-styleguide/blob/master/wemake_python_styleguide/visitors/ast/complexity/counts.py#L89

After that we can detect its complexity.
But, currently we only count regular `def`s. We need to count `async def`s as well.

What need to be done?
1. We need to create a new node handler is the visitor: `visit_any_function`
2. We need to alias `visit_AsyncFunctionDef`, `visit_FunctionDef` to `visit_any_function`
3. We need to add new unit tests for `async` methods: https://github.com/wemake-services/wemake-python-styleguide/blob/master/tests/test_visitors/test_ast/test_complexity/test_counts/test_method_counts.py



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `wemake_python_styleguide/visitors/ast/complexity/counts.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 import ast
4 from collections import defaultdict
5 from typing import DefaultDict, Union
6 
7 from wemake_python_styleguide.logics.functions import is_method
8 from wemake_python_styleguide.types import AnyImport
9 from wemake_python_styleguide.violations.complexity import (
10     TooManyConditionsViolation,
11     TooManyImportsViolation,
12     TooManyMethodsViolation,
13     TooManyModuleMembersViolation,
14 )
15 from wemake_python_styleguide.visitors.base import BaseNodeVisitor
16 from wemake_python_styleguide.visitors.decorators import alias
17 
18 ConditionNodes = Union[ast.If, ast.While, ast.IfExp]
19 ModuleMembers = Union[ast.AsyncFunctionDef, ast.FunctionDef, ast.ClassDef]
20 
21 
22 @alias('visit_module_members', (
23     'visit_ClassDef',
24     'visit_AsyncFunctionDef',
25     'visit_FunctionDef',
26 ))
27 class ModuleMembersVisitor(BaseNodeVisitor):
28     """Counts classes and functions in a module."""
29 
30     def __init__(self, *args, **kwargs) -> None:
31         """Creates a counter for tracked metrics."""
32         super().__init__(*args, **kwargs)
33         self._public_items_count = 0
34 
35     def _check_members_count(self, node: ModuleMembers) -> None:
36         """This method increases the number of module members."""
37         parent = getattr(node, 'parent', None)
38         is_real_method = is_method(getattr(node, 'function_type', None))
39 
40         if isinstance(parent, ast.Module) and not is_real_method:
41             self._public_items_count += 1
42 
43     def _post_visit(self) -> None:
44         if self._public_items_count > self.options.max_module_members:
45             self.add_violation(TooManyModuleMembersViolation())
46 
47     def visit_module_members(self, node: ModuleMembers) -> None:
48         """
49         Counts the number of ModuleMembers in a single module.
50 
51         Raises:
52             TooManyModuleMembersViolation
53 
54         """
55         self._check_members_count(node)
56         self.generic_visit(node)
57 
58 
59 @alias('visit_any_import', (
60     'visit_ImportFrom',
61     'visit_Import',
62 ))
63 class ImportMembersVisitor(BaseNodeVisitor):
64     """Counts imports in a module."""
65 
66     def __init__(self, *args, **kwargs) -> None:
67         """Creates a counter for tracked metrics."""
68         super().__init__(*args, **kwargs)
69         self._imports_count = 0
70 
71     def _post_visit(self) -> None:
72         if self._imports_count > self.options.max_imports:
73             self.add_violation(
74                 TooManyImportsViolation(text=str(self._imports_count)),
75             )
76 
77     def visit_any_import(self, node: AnyImport) -> None:
78         """
79         Counts the number of ``import`` and ``from ... import ...``.
80 
81         Raises:
82             TooManyImportsViolation
83 
84         """
85         self._imports_count += 1
86         self.generic_visit(node)
87 
88 
89 class MethodMembersVisitor(BaseNodeVisitor):
90     """Counts methods in a single class."""
91 
92     def __init__(self, *args, **kwargs) -> None:
93         """Creates a counter for tracked methods in different classes."""
94         super().__init__(*args, **kwargs)
95         self._methods: DefaultDict[ast.ClassDef, int] = defaultdict(int)
96 
97     def _check_method(self, node: ast.FunctionDef) -> None:
98         parent = getattr(node, 'parent', None)
99         if isinstance(parent, ast.ClassDef):
100             self._methods[parent] += 1
101 
102     def _post_visit(self) -> None:
103         for node, count in self._methods.items():
104             if count > self.options.max_methods:
105                 self.add_violation(TooManyMethodsViolation(text=node.name))
106 
107     def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
108         """
109         Counts the number of methods in a single class.
110 
111         Raises:
112             TooManyMethodsViolation
113 
114         """
115         self._check_method(node)
116         self.generic_visit(node)
117 
118 
119 @alias('visit_condition', (
120     'visit_While',
121     'visit_IfExp',
122     'visit_If',
123 ))
124 class ConditionsVisitor(BaseNodeVisitor):
125     """Checks ``if`` and ``while`` statements for condition counts."""
126 
127     def __init__(self, *args, **kwargs) -> None:
128         """Creates a counter for tracked conditions."""
129         super().__init__(*args, **kwargs)
130         self._conditions: DefaultDict[ast.AST, int] = defaultdict(int)
131 
132     def _check_conditions(self, node: ast.AST) -> None:
133         for condition in ast.walk(node):
134             if isinstance(condition, (ast.And, ast.Or)):
135                 self._conditions[node] += 1
136 
137     def _post_visit(self) -> None:
138         for node, count in self._conditions.items():
139             if count > self.options.max_conditions - 1:
140                 self.add_violation(
141                     TooManyConditionsViolation(node, text=str(count)),
142                 )
143 
144     def visit_comprehension(self, node: ast.comprehension) -> None:
145         """
146         Counts the number of conditions in list comprehensions.
147 
148         Raises:
149             TooManyConditionsViolation
150 
151         """
152         if node.ifs:
153             # We only check the first `if`, since it is forbidden
154             # to have more than one at a time
155             # by `MultipleIfsInComprehensionViolation`
156             self._check_conditions(node.ifs[0])
157         self.generic_visit(node)
158 
159     def visit_condition(self, node: ConditionNodes) -> None:
160         """
161         Counts the number of conditions.
162 
163         Raises:
164             TooManyConditionsViolation
165 
166         """
167         self._check_conditions(node.test)
168         self.generic_visit(node)
169
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/wemake_python_styleguide/visitors/ast/complexity/counts.py b/wemake_python_styleguide/visitors/ast/complexity/counts.py
--- a/wemake_python_styleguide/visitors/ast/complexity/counts.py
+++ b/wemake_python_styleguide/visitors/ast/complexity/counts.py
@@ -17,6 +17,7 @@
 
 ConditionNodes = Union[ast.If, ast.While, ast.IfExp]
 ModuleMembers = Union[ast.AsyncFunctionDef, ast.FunctionDef, ast.ClassDef]
+MethodMembers = Union[ast.FunctionDef, ast.AsyncFunctionDef]
 
 
 @alias('visit_module_members', (
@@ -86,6 +87,10 @@
         self.generic_visit(node)
 
 
+@alias('visit_any_function', (
+    'visit_FunctionDef',
+    'visit_AsyncFunctionDef',
+))
 class MethodMembersVisitor(BaseNodeVisitor):
     """Counts methods in a single class."""
 
@@ -94,7 +99,7 @@
         super().__init__(*args, **kwargs)
         self._methods: DefaultDict[ast.ClassDef, int] = defaultdict(int)
 
-    def _check_method(self, node: ast.FunctionDef) -> None:
+    def _check_method(self, node: MethodMembers) -> None:
         parent = getattr(node, 'parent', None)
         if isinstance(parent, ast.ClassDef):
             self._methods[parent] += 1
@@ -104,7 +109,7 @@
             if count > self.options.max_methods:
                 self.add_violation(TooManyMethodsViolation(text=node.name))
 
-    def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
+    def visit_any_function(self, node: MethodMembers) -> None:
         """
         Counts the number of methods in a single class.

{"golden_diff": "diff --git a/wemake_python_styleguide/visitors/ast/complexity/counts.py b/wemake_python_styleguide/visitors/ast/complexity/counts.py\n--- a/wemake_python_styleguide/visitors/ast/complexity/counts.py\n+++ b/wemake_python_styleguide/visitors/ast/complexity/counts.py\n@@ -17,6 +17,7 @@\n \n ConditionNodes = Union[ast.If, ast.While, ast.IfExp]\n ModuleMembers = Union[ast.AsyncFunctionDef, ast.FunctionDef, ast.ClassDef]\n+MethodMembers = Union[ast.FunctionDef, ast.AsyncFunctionDef]\n \n \n @alias('visit_module_members', (\n@@ -86,6 +87,10 @@\n         self.generic_visit(node)\n \n \n+@alias('visit_any_function', (\n+    'visit_FunctionDef',\n+    'visit_AsyncFunctionDef',\n+))\n class MethodMembersVisitor(BaseNodeVisitor):\n     \"\"\"Counts methods in a single class.\"\"\"\n \n@@ -94,7 +99,7 @@\n         super().__init__(*args, **kwargs)\n         self._methods: DefaultDict[ast.ClassDef, int] = defaultdict(int)\n \n-    def _check_method(self, node: ast.FunctionDef) -> None:\n+    def _check_method(self, node: MethodMembers) -> None:\n         parent = getattr(node, 'parent', None)\n         if isinstance(parent, ast.ClassDef):\n             self._methods[parent] += 1\n@@ -104,7 +109,7 @@\n             if count > self.options.max_methods:\n                 self.add_violation(TooManyMethodsViolation(text=node.name))\n \n-    def visit_FunctionDef(self, node: ast.FunctionDef) -> None:\n+    def visit_any_function(self, node: MethodMembers) -> None:\n         \"\"\"\n         Counts the number of methods in a single class.\n", "issue": "Feature: count async methods as methods inside classes\nHere we count how many methods the class has: https://github.com/wemake-services/wemake-python-styleguide/blob/master/wemake_python_styleguide/visitors/ast/complexity/counts.py#L89\r\n\r\nAfter that we can detect its complexity.\r\nBut, currently we only count regular `def`s. We need to count `async def`s as well.\r\n\r\nWhat need to be done?\r\n1. We need to create a new node handler is the visitor: `visit_any_function`\r\n2. We need to alias `visit_AsyncFunctionDef`, `visit_FunctionDef` to `visit_any_function`\r\n3. We need to add new unit tests for `async` methods: https://github.com/wemake-services/wemake-python-styleguide/blob/master/tests/test_visitors/test_ast/test_complexity/test_counts/test_method_counts.py\r\n\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport ast\nfrom collections import defaultdict\nfrom typing import DefaultDict, Union\n\nfrom wemake_python_styleguide.logics.functions import is_method\nfrom wemake_python_styleguide.types import AnyImport\nfrom wemake_python_styleguide.violations.complexity import (\n    TooManyConditionsViolation,\n    TooManyImportsViolation,\n    TooManyMethodsViolation,\n    TooManyModuleMembersViolation,\n)\nfrom wemake_python_styleguide.visitors.base import BaseNodeVisitor\nfrom wemake_python_styleguide.visitors.decorators import alias\n\nConditionNodes = Union[ast.If, ast.While, ast.IfExp]\nModuleMembers = Union[ast.AsyncFunctionDef, ast.FunctionDef, ast.ClassDef]\n\n\n@alias('visit_module_members', (\n    'visit_ClassDef',\n    'visit_AsyncFunctionDef',\n    'visit_FunctionDef',\n))\nclass ModuleMembersVisitor(BaseNodeVisitor):\n    \"\"\"Counts classes and functions in a module.\"\"\"\n\n    def __init__(self, *args, **kwargs) -> None:\n        \"\"\"Creates a counter for tracked metrics.\"\"\"\n        super().__init__(*args, **kwargs)\n        self._public_items_count = 0\n\n    def _check_members_count(self, node: ModuleMembers) -> None:\n        \"\"\"This method increases the number of module members.\"\"\"\n        parent = getattr(node, 'parent', None)\n        is_real_method = is_method(getattr(node, 'function_type', None))\n\n        if isinstance(parent, ast.Module) and not is_real_method:\n            self._public_items_count += 1\n\n    def _post_visit(self) -> None:\n        if self._public_items_count > self.options.max_module_members:\n            self.add_violation(TooManyModuleMembersViolation())\n\n    def visit_module_members(self, node: ModuleMembers) -> None:\n        \"\"\"\n        Counts the number of ModuleMembers in a single module.\n\n        Raises:\n            TooManyModuleMembersViolation\n\n        \"\"\"\n        self._check_members_count(node)\n        self.generic_visit(node)\n\n\n@alias('visit_any_import', (\n    'visit_ImportFrom',\n    'visit_Import',\n))\nclass ImportMembersVisitor(BaseNodeVisitor):\n    \"\"\"Counts imports in a module.\"\"\"\n\n    def __init__(self, *args, **kwargs) -> None:\n        \"\"\"Creates a counter for tracked metrics.\"\"\"\n        super().__init__(*args, **kwargs)\n        self._imports_count = 0\n\n    def _post_visit(self) -> None:\n        if self._imports_count > self.options.max_imports:\n            self.add_violation(\n                TooManyImportsViolation(text=str(self._imports_count)),\n            )\n\n    def visit_any_import(self, node: AnyImport) -> None:\n        \"\"\"\n        Counts the number of ``import`` and ``from ... import ...``.\n\n        Raises:\n            TooManyImportsViolation\n\n        \"\"\"\n        self._imports_count += 1\n        self.generic_visit(node)\n\n\nclass MethodMembersVisitor(BaseNodeVisitor):\n    \"\"\"Counts methods in a single class.\"\"\"\n\n    def __init__(self, *args, **kwargs) -> None:\n        \"\"\"Creates a counter for tracked methods in different classes.\"\"\"\n        super().__init__(*args, **kwargs)\n        self._methods: DefaultDict[ast.ClassDef, int] = defaultdict(int)\n\n    def _check_method(self, node: ast.FunctionDef) -> None:\n        parent = getattr(node, 'parent', None)\n        if isinstance(parent, ast.ClassDef):\n            self._methods[parent] += 1\n\n    def _post_visit(self) -> None:\n        for node, count in self._methods.items():\n            if count > self.options.max_methods:\n                self.add_violation(TooManyMethodsViolation(text=node.name))\n\n    def visit_FunctionDef(self, node: ast.FunctionDef) -> None:\n        \"\"\"\n        Counts the number of methods in a single class.\n\n        Raises:\n            TooManyMethodsViolation\n\n        \"\"\"\n        self._check_method(node)\n        self.generic_visit(node)\n\n\n@alias('visit_condition', (\n    'visit_While',\n    'visit_IfExp',\n    'visit_If',\n))\nclass ConditionsVisitor(BaseNodeVisitor):\n    \"\"\"Checks ``if`` and ``while`` statements for condition counts.\"\"\"\n\n    def __init__(self, *args, **kwargs) -> None:\n        \"\"\"Creates a counter for tracked conditions.\"\"\"\n        super().__init__(*args, **kwargs)\n        self._conditions: DefaultDict[ast.AST, int] = defaultdict(int)\n\n    def _check_conditions(self, node: ast.AST) -> None:\n        for condition in ast.walk(node):\n            if isinstance(condition, (ast.And, ast.Or)):\n                self._conditions[node] += 1\n\n    def _post_visit(self) -> None:\n        for node, count in self._conditions.items():\n            if count > self.options.max_conditions - 1:\n                self.add_violation(\n                    TooManyConditionsViolation(node, text=str(count)),\n                )\n\n    def visit_comprehension(self, node: ast.comprehension) -> None:\n        \"\"\"\n        Counts the number of conditions in list comprehensions.\n\n        Raises:\n            TooManyConditionsViolation\n\n        \"\"\"\n        if node.ifs:\n            # We only check the first `if`, since it is forbidden\n            # to have more than one at a time\n            # by `MultipleIfsInComprehensionViolation`\n            self._check_conditions(node.ifs[0])\n        self.generic_visit(node)\n\n    def visit_condition(self, node: ConditionNodes) -> None:\n        \"\"\"\n        Counts the number of conditions.\n\n        Raises:\n            TooManyConditionsViolation\n\n        \"\"\"\n        self._check_conditions(node.test)\n        self.generic_visit(node)\n", "path": "wemake_python_styleguide/visitors/ast/complexity/counts.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport ast\nfrom collections import defaultdict\nfrom typing import DefaultDict, Union\n\nfrom wemake_python_styleguide.logics.functions import is_method\nfrom wemake_python_styleguide.types import AnyImport\nfrom wemake_python_styleguide.violations.complexity import (\n    TooManyConditionsViolation,\n    TooManyImportsViolation,\n    TooManyMethodsViolation,\n    TooManyModuleMembersViolation,\n)\nfrom wemake_python_styleguide.visitors.base import BaseNodeVisitor\nfrom wemake_python_styleguide.visitors.decorators import alias\n\nConditionNodes = Union[ast.If, ast.While, ast.IfExp]\nModuleMembers = Union[ast.AsyncFunctionDef, ast.FunctionDef, ast.ClassDef]\nMethodMembers = Union[ast.FunctionDef, ast.AsyncFunctionDef]\n\n\n@alias('visit_module_members', (\n    'visit_ClassDef',\n    'visit_AsyncFunctionDef',\n    'visit_FunctionDef',\n))\nclass ModuleMembersVisitor(BaseNodeVisitor):\n    \"\"\"Counts classes and functions in a module.\"\"\"\n\n    def __init__(self, *args, **kwargs) -> None:\n        \"\"\"Creates a counter for tracked metrics.\"\"\"\n        super().__init__(*args, **kwargs)\n        self._public_items_count = 0\n\n    def _check_members_count(self, node: ModuleMembers) -> None:\n        \"\"\"This method increases the number of module members.\"\"\"\n        parent = getattr(node, 'parent', None)\n        is_real_method = is_method(getattr(node, 'function_type', None))\n\n        if isinstance(parent, ast.Module) and not is_real_method:\n            self._public_items_count += 1\n\n    def _post_visit(self) -> None:\n        if self._public_items_count > self.options.max_module_members:\n            self.add_violation(TooManyModuleMembersViolation())\n\n    def visit_module_members(self, node: ModuleMembers) -> None:\n        \"\"\"\n        Counts the number of ModuleMembers in a single module.\n\n        Raises:\n            TooManyModuleMembersViolation\n\n        \"\"\"\n        self._check_members_count(node)\n        self.generic_visit(node)\n\n\n@alias('visit_any_import', (\n    'visit_ImportFrom',\n    'visit_Import',\n))\nclass ImportMembersVisitor(BaseNodeVisitor):\n    \"\"\"Counts imports in a module.\"\"\"\n\n    def __init__(self, *args, **kwargs) -> None:\n        \"\"\"Creates a counter for tracked metrics.\"\"\"\n        super().__init__(*args, **kwargs)\n        self._imports_count = 0\n\n    def _post_visit(self) -> None:\n        if self._imports_count > self.options.max_imports:\n            self.add_violation(\n                TooManyImportsViolation(text=str(self._imports_count)),\n            )\n\n    def visit_any_import(self, node: AnyImport) -> None:\n        \"\"\"\n        Counts the number of ``import`` and ``from ... import ...``.\n\n        Raises:\n            TooManyImportsViolation\n\n        \"\"\"\n        self._imports_count += 1\n        self.generic_visit(node)\n\n\n@alias('visit_any_function', (\n    'visit_FunctionDef',\n    'visit_AsyncFunctionDef',\n))\nclass MethodMembersVisitor(BaseNodeVisitor):\n    \"\"\"Counts methods in a single class.\"\"\"\n\n    def __init__(self, *args, **kwargs) -> None:\n        \"\"\"Creates a counter for tracked methods in different classes.\"\"\"\n        super().__init__(*args, **kwargs)\n        self._methods: DefaultDict[ast.ClassDef, int] = defaultdict(int)\n\n    def _check_method(self, node: MethodMembers) -> None:\n        parent = getattr(node, 'parent', None)\n        if isinstance(parent, ast.ClassDef):\n            self._methods[parent] += 1\n\n    def _post_visit(self) -> None:\n        for node, count in self._methods.items():\n            if count > self.options.max_methods:\n                self.add_violation(TooManyMethodsViolation(text=node.name))\n\n    def visit_any_function(self, node: MethodMembers) -> None:\n        \"\"\"\n        Counts the number of methods in a single class.\n\n        Raises:\n            TooManyMethodsViolation\n\n        \"\"\"\n        self._check_method(node)\n        self.generic_visit(node)\n\n\n@alias('visit_condition', (\n    'visit_While',\n    'visit_IfExp',\n    'visit_If',\n))\nclass ConditionsVisitor(BaseNodeVisitor):\n    \"\"\"Checks ``if`` and ``while`` statements for condition counts.\"\"\"\n\n    def __init__(self, *args, **kwargs) -> None:\n        \"\"\"Creates a counter for tracked conditions.\"\"\"\n        super().__init__(*args, **kwargs)\n        self._conditions: DefaultDict[ast.AST, int] = defaultdict(int)\n\n    def _check_conditions(self, node: ast.AST) -> None:\n        for condition in ast.walk(node):\n            if isinstance(condition, (ast.And, ast.Or)):\n                self._conditions[node] += 1\n\n    def _post_visit(self) -> None:\n        for node, count in self._conditions.items():\n            if count > self.options.max_conditions - 1:\n                self.add_violation(\n                    TooManyConditionsViolation(node, text=str(count)),\n                )\n\n    def visit_comprehension(self, node: ast.comprehension) -> None:\n        \"\"\"\n        Counts the number of conditions in list comprehensions.\n\n        Raises:\n            TooManyConditionsViolation\n\n        \"\"\"\n        if node.ifs:\n            # We only check the first `if`, since it is forbidden\n            # to have more than one at a time\n            # by `MultipleIfsInComprehensionViolation`\n            self._check_conditions(node.ifs[0])\n        self.generic_visit(node)\n\n    def visit_condition(self, node: ConditionNodes) -> None:\n        \"\"\"\n        Counts the number of conditions.\n\n        Raises:\n            TooManyConditionsViolation\n\n        \"\"\"\n        self._check_conditions(node.test)\n        self.generic_visit(node)\n", "path": "wemake_python_styleguide/visitors/ast/complexity/counts.py"}]}