(ctx: FunctionContext)
| 53 | |
| 54 | |
| 55 | def isinstance_proper_hook(ctx: FunctionContext) -> Type: |
| 56 | if len(ctx.arg_types) != 2 or not ctx.arg_types[1]: |
| 57 | return ctx.default_return_type |
| 58 | |
| 59 | right = get_proper_type(ctx.arg_types[1][0]) |
| 60 | for arg in ctx.arg_types[0]: |
| 61 | if ( |
| 62 | is_improper_type(arg) or isinstance(get_proper_type(arg), AnyType) |
| 63 | ) and is_dangerous_target(right): |
| 64 | if is_special_target(right): |
| 65 | return ctx.default_return_type |
| 66 | ctx.api.fail( |
| 67 | "Never apply isinstance() to unexpanded types;" |
| 68 | " use mypy.types.get_proper_type() first", |
| 69 | ctx.context, |
| 70 | ) |
| 71 | ctx.api.note( # type: ignore[attr-defined] |
| 72 | "If you pass on the original type" |
| 73 | " after the check, always use its unexpanded version", |
| 74 | ctx.context, |
| 75 | ) |
| 76 | return ctx.default_return_type |
| 77 | |
| 78 | |
| 79 | def is_special_target(right: ProperType) -> bool: |
nothing calls this directly
no test coverage detected
searching dependent graphs…