Skip to content

Commit 4d3cf11

Browse files
no_implicit_any: fix crash on class keywords (#34)
1 parent 6800956 commit 4d3cf11

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

docs/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Fix crash on class definition keyword args when the `no_implicit_any` error
6+
is enabled.
57
- Fix incorrect treatment of `ParamSpec` in certain contexts.
68
- Add basic support for intersection types with `pycroscope.extensions.Intersection`.
79
- Fix crash on checking the boolability of certain complex types.

pycroscope/name_check_visitor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,8 @@ def visit_ClassDef(self, node: ast.ClassDef) -> Value:
17861786
if sys.version_info >= (3, 12) and node.type_params:
17871787
self.visit_type_param_values(node.type_params)
17881788
self._generic_visit_list(node.bases)
1789-
self._generic_visit_list(node.keywords)
1789+
for kw in node.keywords:
1790+
self.visit(kw.value)
17901791
value = self._visit_class_and_get_value(node, class_obj)
17911792
value, _ = self._set_name_in_scope(node.name, node, value)
17921793
return value
@@ -5466,14 +5467,13 @@ def _should_ignore_val(self, node: ast.AST) -> bool:
54665467

54675468
# Call nodes
54685469

5469-
def visit_keyword(self, node: ast.keyword) -> tuple[Optional[str], Composite]:
5470-
return (node.arg, self.composite_from_node(node.value))
5471-
54725470
def visit_Call(self, node: ast.Call) -> Value:
54735471
callee_wrapped = self.visit(node.func)
54745472
args = [self.composite_from_node(arg) for arg in node.args]
54755473
if node.keywords:
5476-
keywords = [self.visit_keyword(kw) for kw in node.keywords]
5474+
keywords = [
5475+
(kw.arg, self.composite_from_node(kw.value)) for kw in node.keywords
5476+
]
54775477
else:
54785478
keywords = []
54795479

pycroscope/test_name_check_visitor.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,3 +2306,14 @@ async def gen() -> AsyncGenerator[int, None]:
23062306

23072307
def capybara() -> None:
23082308
gen() # E: must_use
2309+
2310+
2311+
class TestImplicitAny(TestNameCheckVisitorBase):
2312+
@assert_passes(settings={ErrorCode.implicit_any: True})
2313+
def test_class_args(self):
2314+
class Base:
2315+
def __init_subclass__(cls, **kwargs) -> None:
2316+
pass
2317+
2318+
class X(Base, a=True):
2319+
pass

0 commit comments

Comments
 (0)