mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 22:54:42 +00:00
Update class literal display to use <class 'Foo'>
style (#17889)
## Summary Closes https://github.com/astral-sh/ruff/issues/17238.
This commit is contained in:
parent
b2de749c32
commit
a2e9a7732a
48 changed files with 311 additions and 309 deletions
|
@ -29,7 +29,7 @@ class RepeatedTypevar(Generic[T, T]): ...
|
|||
You can only specialize `typing.Generic` with typevars (TODO: or param specs or typevar tuples).
|
||||
|
||||
```py
|
||||
# error: [invalid-argument-type] "`Literal[int]` is not a valid argument to `typing.Generic`"
|
||||
# error: [invalid-argument-type] "`<class 'int'>` is not a valid argument to `typing.Generic`"
|
||||
class GenericOfType(Generic[int]): ...
|
||||
```
|
||||
|
||||
|
@ -436,7 +436,7 @@ T = TypeVar("T")
|
|||
class Base(Generic[T]): ...
|
||||
class Sub(Base[Sub]): ...
|
||||
|
||||
reveal_type(Sub) # revealed: Literal[Sub]
|
||||
reveal_type(Sub) # revealed: <class 'Sub'>
|
||||
```
|
||||
|
||||
#### With string forward references
|
||||
|
@ -451,7 +451,7 @@ T = TypeVar("T")
|
|||
class Base(Generic[T]): ...
|
||||
class Sub(Base["Sub"]): ...
|
||||
|
||||
reveal_type(Sub) # revealed: Literal[Sub]
|
||||
reveal_type(Sub) # revealed: <class 'Sub'>
|
||||
```
|
||||
|
||||
#### Without string forward references
|
||||
|
|
|
@ -19,7 +19,7 @@ in newer Python releases.
|
|||
from typing import TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
reveal_type(type(T)) # revealed: Literal[TypeVar]
|
||||
reveal_type(type(T)) # revealed: <class 'TypeVar'>
|
||||
reveal_type(T) # revealed: typing.TypeVar
|
||||
reveal_type(T.__name__) # revealed: Literal["T"]
|
||||
```
|
||||
|
|
|
@ -362,7 +362,7 @@ Here, `Sub` is not a generic class, since it fills its superclass's type paramet
|
|||
class Base[T]: ...
|
||||
class Sub(Base[Sub]): ...
|
||||
|
||||
reveal_type(Sub) # revealed: Literal[Sub]
|
||||
reveal_type(Sub) # revealed: <class 'Sub'>
|
||||
```
|
||||
|
||||
#### With string forward references
|
||||
|
@ -373,7 +373,7 @@ A similar case can work in a non-stub file, if forward references are stringifie
|
|||
class Base[T]: ...
|
||||
class Sub(Base["Sub"]): ...
|
||||
|
||||
reveal_type(Sub) # revealed: Literal[Sub]
|
||||
reveal_type(Sub) # revealed: <class 'Sub'>
|
||||
```
|
||||
|
||||
#### Without string forward references
|
||||
|
|
|
@ -16,7 +16,7 @@ instances of `typing.TypeVar`, just like legacy type variables.
|
|||
|
||||
```py
|
||||
def f[T]():
|
||||
reveal_type(type(T)) # revealed: Literal[TypeVar]
|
||||
reveal_type(type(T)) # revealed: <class 'TypeVar'>
|
||||
reveal_type(T) # revealed: typing.TypeVar
|
||||
reveal_type(T.__name__) # revealed: Literal["T"]
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue