Skip to content

Commit

Permalink
[red-knot] Add failing test for use of type[] as a base class (#14913)
Browse files Browse the repository at this point in the history
We support using `typing.Type[]` as a base class (and we have tests for
it), but not yet `builtins.type[]`. At some point we should fix that,
but I don't think it';s worth spending much time on now (and it might be
easier once we've implemented generics?). This PR just adds a failing
test with a TODO.
  • Loading branch information
AlexWaygood authored Dec 11, 2024
1 parent ef153a0 commit a543533
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/red_knot_python_semantic/resources/mdtest/type_of/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,14 @@ class B: ...
# error: [invalid-type-form]
_: type[A, B]
```

## As a base class

```py
# TODO: this is a false positive
# error: [invalid-base] "Invalid class base with type `GenericAlias` (all bases must be a class, `Any`, `Unknown` or `Todo`)"
class Foo(type[int]): ...

# TODO: should be `tuple[Literal[Foo], Literal[type], Literal[object]]
reveal_type(Foo.__mro__) # revealed: tuple[Literal[Foo], Unknown, Literal[object]]
```

0 comments on commit a543533

Please # to comment.