ruff/crates/ty_python_semantic/resources/mdtest
David Peter 9e80e5a3a6
[ty] Support type[…] and Type[…] in implicit type aliases (#21421)
## Summary

Support `type[…]` in implicit type aliases, for example:
```py
SubclassOfInt = type[int]

reveal_type(SubclassOfInt)  # GenericAlias

def _(subclass_of_int: SubclassOfInt):
    reveal_type(subclass_of_int)  # type[int]
```

part of https://github.com/astral-sh/ty/issues/221

## Typing conformance

```diff
-specialtypes_type.py:138:5: error[type-assertion-failure] Argument does not have asserted type `type[Any]`
-specialtypes_type.py:140:5: error[type-assertion-failure] Argument does not have asserted type `type[Any]`
```

Two new tests passing ✔️ 

```diff
-specialtypes_type.py:146:1: error[unresolved-attribute] Object of type `GenericAlias` has no attribute `unknown`
```

An `TA4.unknown` attribute on a PEP 613 alias (`TA4: TypeAlias =
type[Any]`) is being accessed, and the conformance suite expects this to
be an error. Since we currently use the inferred type for these type
aliases (and possibly in the future as well), we treat this as a direct
access of the attribute on `type[Any]`, which falls back to an access on
`Any` itself, which succeeds. 🔴

```
+specialtypes_type.py:152:16: error[invalid-type-form] `typing.TypeVar` is not a generic class
+specialtypes_type.py:156:16: error[invalid-type-form] `typing.TypeVar` is not a generic class
```

New errors because we don't handle `T = TypeVar("T"); MyType = type[T];
MyType[T]` yet. Support for this is being tracked in
https://github.com/astral-sh/ty/issues/221 🔴

## Ecosystem impact

Looks mostly good, a few known problems. 

## Test Plan

New Markdown tests
2025-11-13 19:02:24 +01:00
..
annotations [ty] Ensure annotation/type expressions in stub files are always deferred (#21401) 2025-11-13 17:14:54 +00:00
assignment [ty] Handle annotated self parameter in constructor of non-invariant generic classes (#21325) 2025-11-10 19:46:49 -05:00
binary [ty] Rename UnionType to types.UnionType (#21262) 2025-11-03 22:06:56 +01:00
boolean
boundness_declaredness
call [ty] Silence false-positive diagnostics when using typing.Dict or typing.Callable as the second argument to isinstance() (#21386) 2025-11-11 19:30:01 +00:00
class [ty] implement typing.NewType by adding Type::NewTypeInstance 2025-11-10 14:55:47 -08:00
comparison
comprehensions [ty] fix global symbol lookup from eager scopes (#21317) 2025-11-12 10:15:51 -08:00
conditional
dataclasses [ty] Improve generic call expression inference (#21210) 2025-11-10 21:29:05 +00:00
declaration
diagnostics
directives
doc
exception
expression [ty] Use "cannot" consistently over "can not" (#21255) 2025-11-03 10:38:20 -05:00
function [ty] don't union in default type for annotated parameters (#21208) 2025-11-02 18:21:54 -05:00
generics [ty] Ensure annotation/type expressions in stub files are always deferred (#21401) 2025-11-13 17:14:54 +00:00
ide_support [ty] Use "cannot" consistently over "can not" (#21255) 2025-11-03 10:38:20 -05:00
import [ty] Consider from thispackage import y to re-export y in __init__.pyi (#21387) 2025-11-11 14:41:14 -05:00
literal [ty] Type inference for comprehensions (#20962) 2025-11-02 14:35:33 +01:00
loops [ty] Fix bug where ty would think all types had an __mro__ attribute (#20995) 2025-10-27 11:19:12 +00:00
narrow [ty] Ensure annotation/type expressions in stub files are always deferred (#21401) 2025-11-13 17:14:54 +00:00
regression [ty] fix global symbol lookup from eager scopes (#21317) 2025-11-12 10:15:51 -08:00
scopes [ty] Improve error messages for unresolved attribute diagnostics (#20963) 2025-10-19 10:58:25 +01:00
shadowing
snapshots [ty] Further improve subscript assignment diagnostics (#21411) 2025-11-13 13:31:14 +01:00
stubs [ty] Fix bug where ty would think all types had an __mro__ attribute (#20995) 2025-10-27 11:19:12 +00:00
subscript [ty] Further improve subscript assignment diagnostics (#21411) 2025-11-13 13:31:14 +01:00
suppressions
type_compendium [ty] Use "cannot" consistently over "can not" (#21255) 2025-11-03 10:38:20 -05:00
type_of [ty] Support type[…] and Type[…] in implicit type aliases (#21421) 2025-11-13 19:02:24 +01:00
type_properties [ty] introduce local variables for from imports of submodules in __init__.py(i) (#21173) 2025-11-10 23:04:56 +00:00
type_qualifiers [ty] Fix false positive for Final attribute assignment in __init__ (#21158) 2025-11-11 12:54:05 -08:00
unary
with
.mdformat.toml
async.md
attributes.md [ty] Skip eagerly evaluated scopes for attribute storing (#20856) 2025-11-11 14:45:34 -08:00
bidirectional.md [ty] Improve generic call expression inference (#21210) 2025-11-10 21:29:05 +00:00
classes.md [ty] Fix bug where ty would think all types had an __mro__ attribute (#20995) 2025-10-27 11:19:12 +00:00
cycle.md [ty] Avoid ever-growing default types (#20991) 2025-10-21 19:13:36 +02:00
decorators.md
del.md
deprecated.md
descriptor_protocol.md [ty] Use the return type of __get__ for descriptor lookups even when __get__ is called with incorrect arguments (#21424) 2025-11-13 12:05:10 +00:00
enums.md [ty] Fix incorrect inference of enum.auto() for enums with non-int mixins, and imprecise inference of enum.auto() for single-member enums (#20541) 2025-11-10 17:53:08 +00:00
exhaustiveness_checking.md [ty] Improve exhaustiveness analysis for type variables with bounds or constraints (#21172) 2025-10-31 16:51:11 -04:00
final.md
implicit_type_aliases.md [ty] Support type[…] and Type[…] in implicit type aliases (#21421) 2025-11-13 19:02:24 +01:00
instance_layout_conflict.md
intersection_types.md [ty] Use "cannot" consistently over "can not" (#21255) 2025-11-03 10:38:20 -05:00
invalid_syntax.md [ty] Implicit type aliases: Add support for typing.Union (#21363) 2025-11-12 12:59:14 +01:00
known_constants.md
literal_promotion.md [ty] Do not promote literals in contravariant positions of generic specializations (#21171) 2025-10-31 17:48:34 +01:00
mdtest_config.md
mdtest_custom_typeshed.md
metaclass.md
mro.md [ty] Rename UnionType to types.UnionType (#21262) 2025-11-03 22:06:56 +01:00
named_tuple.md [ty] Fix bug where ty would think all types had an __mro__ attribute (#20995) 2025-10-27 11:19:12 +00:00
overloads.md [ty] Infer type of self for decorated methods and properties (#21123) 2025-10-29 21:22:38 +00:00
paramspec.md [ty] Ensure annotation/type expressions in stub files are always deferred (#21401) 2025-11-13 17:14:54 +00:00
pep613_type_aliases.md [ty] Fall back to Divergent for deeply nested specializations (#20988) 2025-10-22 14:29:10 +02:00
pep695_type_aliases.md [ty] Add cycle handling to lazy_default (#20967) 2025-10-23 10:05:08 +02:00
properties.md [ty] Use the return type of __get__ for descriptor lookups even when __get__ is called with incorrect arguments (#21424) 2025-11-13 12:05:10 +00:00
protocols.md [ty] Fix bug where ty would think all types had an __mro__ attribute (#20995) 2025-10-27 11:19:12 +00:00
public_types.md
statically_known_branches.md
sys_platform.md
sys_version_info.md
t_strings.md
terminal_statements.md
ty_extensions.md [ty] Use "cannot" consistently over "can not" (#21255) 2025-11-03 10:38:20 -05:00
typed_dict.md [ty] Further improve subscript assignment diagnostics (#21411) 2025-11-13 13:31:14 +01:00
union_types.md
unpacking.md
unreachable.md [ty] Use "cannot" consistently over "can not" (#21255) 2025-11-03 10:38:20 -05:00