(self, o: CallExpr, /)
| 357 | self.annotate(o, ann) |
| 358 | |
| 359 | def visit_call_expr(self, o: CallExpr, /) -> None: |
| 360 | super().visit_call_expr(o) |
| 361 | if ( |
| 362 | isinstance(o.callee, RefExpr) |
| 363 | and o.callee.fullname == "builtins.isinstance" |
| 364 | and len(o.args) == 2 |
| 365 | ): |
| 366 | arg = o.args[1] |
| 367 | self.check_isinstance_arg(arg) |
| 368 | elif isinstance(o.callee, RefExpr) and isinstance(o.callee.node, TypeInfo): |
| 369 | info = o.callee.node |
| 370 | class_ir = self.mapper.type_to_ir.get(info) |
| 371 | if (class_ir and not class_ir.is_ext_class) or ( |
| 372 | class_ir is None and not info.fullname.startswith("builtins.") |
| 373 | ): |
| 374 | self.annotate( |
| 375 | o, f'Creating an instance of non-native class "{info.name}" ' + "is slow.", 2 |
| 376 | ) |
| 377 | elif class_ir and class_ir.is_augmented: |
| 378 | self.annotate( |
| 379 | o, |
| 380 | f'Class "{info.name}" is only partially native, and ' |
| 381 | + "constructing an instance is slow.", |
| 382 | 2, |
| 383 | ) |
| 384 | elif isinstance(o.callee, RefExpr) and isinstance(o.callee.node, Decorator): |
| 385 | decorator = o.callee.node |
| 386 | if self.mapper.is_native_ref_expr(o.callee): |
| 387 | self.annotate( |
| 388 | o, |
| 389 | f'Calling a decorated function ("{decorator.name}") is inefficient, even if it\'s native.', |
| 390 | 2, |
| 391 | ) |
| 392 | |
| 393 | def check_isinstance_arg(self, arg: Expression) -> None: |
| 394 | if isinstance(arg, RefExpr): |
nothing calls this directly
no test coverage detected