ruff/crates/red_knot_python_semantic/resources/mdtest
Carl Meyer fa88989ef0
[red-knot] fix detecting a metaclass on a not-explicitly-specialized generic base (#17621)
## Summary

After https://github.com/astral-sh/ruff/pull/17620 (which this PR is
based on), I was looking at other call sites of `Type::into_class_type`,
and I began to feel that _all_ of them were currently buggy due to
silently skipping unspecialized generic class literal types (though in
some cases the bug hadn't shown up yet because we don't understand
legacy generic classes from typeshed), and in every case they would be
better off if an unspecialized generic class literal were implicitly
specialized with the default specialization (which is the usual Python
typing semantics for an unspecialized reference to a generic class),
instead of silently skipped.

So I changed the method to implicitly apply the default specialization,
and added a test that previously failed for detecting metaclasses on an
unspecialized generic base.

I also renamed the method to `to_class_type`, because I feel we have a
strong naming convention where `Type::into_foo` is always a trivial
`const fn` that simply returns `Some()` if the type is of variant `Foo`
and `None` otherwise. Even the existing method (with it handling both
`GenericAlias` and `ClassLiteral`, and distinguishing kinds of
`ClassLiteral`) was stretching this convention, and the new version
definitely breaks that envelope.

## Test Plan

Added a test that failed before this PR.
2025-04-25 06:55:54 -07:00
..
annotations [red-knot] Detect semantic syntax errors (#17463) 2025-04-23 09:52:58 -04:00
assignment [red-knot] Handle explicit class specialization in type expressions (#17434) 2025-04-18 11:49:22 -04:00
binary [red-knot] Add support for overloaded functions (#17366) 2025-04-18 09:57:40 +05:30
boolean [red-knot] Add some narrowing for assignment expressions (#17448) 2025-04-17 17:28:06 -07:00
boundness_declaredness [red-knot] Trust all symbols in stub files (#17588) 2025-04-23 20:07:29 +02:00
call [red-knot] fix collapsing literal and its negation to object (#17605) 2025-04-24 13:55:05 +00:00
class [red-knot] Detect version-related syntax errors (#16379) 2025-04-17 14:00:30 -04:00
comparison [red-knot] Surround intersections with `()` in potentially ambiguous contexts (#17568) 2025-04-23 04:18:20 +00:00
comprehensions [red-knot] Detect semantic syntax errors (#17463) 2025-04-23 09:52:58 -04:00
conditional red_knot_python_semantic: improve diagnostics for unsupported boolean conversions 2025-04-24 11:43:01 -04:00
declaration [red-knot] Avoid undeclared path when raising conflicting declarations (#14958) 2024-12-17 09:49:39 +05:30
diagnostics [syntax-errors] Make `async-comprehension-in-sync-comprehension` more specific (#17460) 2025-04-24 15:45:54 -04:00
directives [red-knot] Handle explicit class specialization in type expressions (#17434) 2025-04-18 11:49:22 -04:00
doc red_knot_python_semantic: replace one use of "old" secondary diagnostic messages 2025-04-10 13:21:00 -04:00
exception [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
expression red_knot_python_semantic: improve diagnostics for unsupported boolean conversions 2025-04-24 11:43:01 -04:00
function [red-knot] Correctly identify protocol classes (#17487) 2025-04-21 16:17:06 +01:00
generics [red-knot] fix inheritance-cycle detection for generic classes (#17620) 2025-04-25 06:55:00 -07:00
import [red-knot] Detect semantic syntax errors (#17463) 2025-04-23 09:52:58 -04:00
literal [red-knot] Migrate `bool`/`str`/`repr` unit tests to Markdown tests (#15534) 2025-01-16 11:21:56 -08:00
loops red_knot_python_semantic: improve diagnostics for unsupported boolean conversions 2025-04-24 11:43:01 -04:00
narrow red_knot_python_semantic: improve diagnostics for unsupported boolean conversions 2025-04-24 11:43:01 -04:00
regression [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
scopes [red-knot] Add mdtests for `global` statement (#17563) 2025-04-23 17:18:42 -04:00
shadowing red_knot_python_semantic: migrate INVALID_ASSIGNMENT for shadowing 2025-04-22 12:08:03 -04:00
snapshots [syntax-errors] Make `async-comprehension-in-sync-comprehension` more specific (#17460) 2025-04-24 15:45:54 -04:00
stubs [red-knot] Detect version-related syntax errors (#16379) 2025-04-17 14:00:30 -04:00
subscript [red-knot] Trust module-level undeclared symbols in stubs (#17577) 2025-04-23 19:31:14 +02:00
suppressions Use python.typing.org for typing documentation links (#17323) 2025-04-09 20:38:20 +02:00
type_of [red-knot] GenericAlias instances as a base class (#17575) 2025-04-23 10:39:10 +02:00
type_properties [red-knot] Assignability of class instances to Callable (#17590) 2025-04-23 20:34:13 +02:00
type_qualifiers [red-knot] Preliminary tests for typing.Final (#15917) 2025-03-14 12:30:13 +01:00
unary red_knot_python_semantic: improve diagnostics for unsupported boolean conversions 2025-04-24 11:43:01 -04:00
with [red-knot] detect invalid return type (#16540) 2025-03-12 01:58:59 +00:00
.mdformat.toml [red-knot] have mdformat wrap mdtest files to 100 columns (#14020) 2024-10-31 21:00:51 +00:00
attributes.md [red-knot] infer attribute assignments bound in comprehensions (#17396) 2025-04-19 06:42:48 +05:30
dataclass_transform.md [red-knot] `typing.dataclass_transform` (#17445) 2025-04-22 10:33:02 +02:00
dataclasses.md [red-knot] `typing.dataclass_transform` (#17445) 2025-04-22 10:33:02 +02:00
decorators.md [red-knot] Handle explicit class specialization in type expressions (#17434) 2025-04-18 11:49:22 -04:00
descriptor_protocol.md [red-knot] Add support for overloaded functions (#17366) 2025-04-18 09:57:40 +05:30
final.md [red-knot] Add support for `@final` classes (#15070) 2024-12-19 21:02:14 +00:00
intersection_types.md [red-knot] Surround intersections with `()` in potentially ambiguous contexts (#17568) 2025-04-23 04:18:20 +00:00
invalid_syntax.md [red-knot] Understand `typing.Callable` (#16493) 2025-03-08 03:58:52 +00:00
known_constants.md [red-knot] Add rule `invalid-type-checking-constant` (#16501) 2025-03-04 19:49:34 +00:00
mdtest_config.md [red-knot] Add missing imports in mdtests (#15869) 2025-02-03 09:27:29 +00:00
mdtest_custom_typeshed.md [red-knot] Assignability for subclasses of `Any` and `Unknown` (#17557) 2025-04-23 11:37:30 +02:00
metaclass.md [red-knot] fix detecting a metaclass on a not-explicitly-specialized generic base (#17621) 2025-04-25 06:55:54 -07:00
mro.md [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) 2025-02-04 08:27:17 +01:00
overloads.md [red-knot] Add support for overloaded functions (#17366) 2025-04-18 09:57:40 +05:30
pep695_type_aliases.md [red-knot] Decorators and properties (#17017) 2025-04-02 09:27:46 +02:00
properties.md [red-knot] improve function/bound method type display (#17294) 2025-04-14 15:56:18 -07:00
protocols.md [red-knot] Add more tests for protocols (#17603) 2025-04-24 13:11:31 +01:00
slots.md [red-knot] fix: improve type inference for binary ops on tuples (#16725) 2025-03-14 12:29:57 +01:00
statically_known_branches.md [red-knot] Detect version-related syntax errors (#16379) 2025-04-17 14:00:30 -04:00
sys_platform.md [red-knot] Specialize `str.startswith` for string literals (#17351) 2025-04-11 16:26:45 +02:00
sys_version_info.md [red-knot] Decorators and properties (#17017) 2025-04-02 09:27:46 +02:00
terminal_statements.md [red-knot] Avoid unresolved-reference in unreachable code (#17169) 2025-04-03 16:52:11 +02:00
type_api.md red_knot_python_semantic: improve diagnostics for unsupported boolean conversions 2025-04-24 11:43:01 -04:00
union_types.md [red-knot] Handle explicit class specialization in type expressions (#17434) 2025-04-18 11:49:22 -04:00
unpacking.md red_knot_python_semantic: migrate INVALID_ASSIGNMENT for unpacking 2025-04-22 12:08:03 -04:00
unreachable.md [red-knot] Document limitations of diagnostics-silencing in unreachable code (#17387) 2025-04-14 12:55:14 +02:00