mirror of https://github.com/astral-sh/ruff
[red-knot] Add `ParamSpecArgs` and `ParamSpecKwargs` as `KnownClass` (#17086)
## Summary In preparation for #17017, where we will need them to suppress new false positives (once we understand the `ParamSpec.args`/`ParamSpec.kwargs` properties). ## Test Plan Tested on branch #17017
This commit is contained in:
parent
0b1ab8fd5a
commit
3d1e5676fb
|
|
@ -56,7 +56,7 @@ def _(
|
||||||
reveal_type(d) # revealed: Unknown
|
reveal_type(d) # revealed: Unknown
|
||||||
|
|
||||||
def foo(a_: e) -> None:
|
def foo(a_: e) -> None:
|
||||||
reveal_type(a_) # revealed: @Todo(Support for `typing.ParamSpec` instances in type expressions)
|
reveal_type(a_) # revealed: @Todo(Support for `typing.ParamSpec`)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Inheritance
|
## Inheritance
|
||||||
|
|
|
||||||
|
|
@ -3089,9 +3089,9 @@ impl<'db> Type<'db> {
|
||||||
Some(KnownClass::TypeVar) => Ok(todo_type!(
|
Some(KnownClass::TypeVar) => Ok(todo_type!(
|
||||||
"Support for `typing.TypeVar` instances in type expressions"
|
"Support for `typing.TypeVar` instances in type expressions"
|
||||||
)),
|
)),
|
||||||
Some(KnownClass::ParamSpec) => Ok(todo_type!(
|
Some(
|
||||||
"Support for `typing.ParamSpec` instances in type expressions"
|
KnownClass::ParamSpec | KnownClass::ParamSpecArgs | KnownClass::ParamSpecKwargs,
|
||||||
)),
|
) => Ok(todo_type!("Support for `typing.ParamSpec`")),
|
||||||
Some(KnownClass::TypeVarTuple) => Ok(todo_type!(
|
Some(KnownClass::TypeVarTuple) => Ok(todo_type!(
|
||||||
"Support for `typing.TypeVarTuple` instances in type expressions"
|
"Support for `typing.TypeVarTuple` instances in type expressions"
|
||||||
)),
|
)),
|
||||||
|
|
|
||||||
|
|
@ -844,6 +844,8 @@ pub enum KnownClass {
|
||||||
SpecialForm,
|
SpecialForm,
|
||||||
TypeVar,
|
TypeVar,
|
||||||
ParamSpec,
|
ParamSpec,
|
||||||
|
ParamSpecArgs,
|
||||||
|
ParamSpecKwargs,
|
||||||
TypeVarTuple,
|
TypeVarTuple,
|
||||||
TypeAliasType,
|
TypeAliasType,
|
||||||
NoDefaultType,
|
NoDefaultType,
|
||||||
|
|
@ -893,6 +895,8 @@ impl<'db> KnownClass {
|
||||||
| Self::TypeAliasType
|
| Self::TypeAliasType
|
||||||
| Self::TypeVar
|
| Self::TypeVar
|
||||||
| Self::ParamSpec
|
| Self::ParamSpec
|
||||||
|
| Self::ParamSpecArgs
|
||||||
|
| Self::ParamSpecKwargs
|
||||||
| Self::TypeVarTuple
|
| Self::TypeVarTuple
|
||||||
| Self::WrapperDescriptorType
|
| Self::WrapperDescriptorType
|
||||||
| Self::MethodWrapperType => Truthiness::AlwaysTrue,
|
| Self::MethodWrapperType => Truthiness::AlwaysTrue,
|
||||||
|
|
@ -969,6 +973,8 @@ impl<'db> KnownClass {
|
||||||
Self::SpecialForm => "_SpecialForm",
|
Self::SpecialForm => "_SpecialForm",
|
||||||
Self::TypeVar => "TypeVar",
|
Self::TypeVar => "TypeVar",
|
||||||
Self::ParamSpec => "ParamSpec",
|
Self::ParamSpec => "ParamSpec",
|
||||||
|
Self::ParamSpecArgs => "ParamSpecArgs",
|
||||||
|
Self::ParamSpecKwargs => "ParamSpecKwargs",
|
||||||
Self::TypeVarTuple => "TypeVarTuple",
|
Self::TypeVarTuple => "TypeVarTuple",
|
||||||
Self::TypeAliasType => "TypeAliasType",
|
Self::TypeAliasType => "TypeAliasType",
|
||||||
Self::NoDefaultType => "_NoDefaultType",
|
Self::NoDefaultType => "_NoDefaultType",
|
||||||
|
|
@ -1149,9 +1155,12 @@ impl<'db> KnownClass {
|
||||||
| Self::StdlibAlias
|
| Self::StdlibAlias
|
||||||
| Self::SupportsIndex
|
| Self::SupportsIndex
|
||||||
| Self::Sized => KnownModule::Typing,
|
| Self::Sized => KnownModule::Typing,
|
||||||
Self::TypeAliasType | Self::TypeVarTuple | Self::ParamSpec | Self::NewType => {
|
Self::TypeAliasType
|
||||||
KnownModule::TypingExtensions
|
| Self::TypeVarTuple
|
||||||
}
|
| Self::ParamSpec
|
||||||
|
| Self::ParamSpecArgs
|
||||||
|
| Self::ParamSpecKwargs
|
||||||
|
| Self::NewType => KnownModule::TypingExtensions,
|
||||||
Self::NoDefaultType => {
|
Self::NoDefaultType => {
|
||||||
let python_version = Program::get(db).python_version(db);
|
let python_version = Program::get(db).python_version(db);
|
||||||
|
|
||||||
|
|
@ -1227,6 +1236,8 @@ impl<'db> KnownClass {
|
||||||
| Self::StdlibAlias
|
| Self::StdlibAlias
|
||||||
| Self::TypeVar
|
| Self::TypeVar
|
||||||
| Self::ParamSpec
|
| Self::ParamSpec
|
||||||
|
| Self::ParamSpecArgs
|
||||||
|
| Self::ParamSpecKwargs
|
||||||
| Self::TypeVarTuple
|
| Self::TypeVarTuple
|
||||||
| Self::Sized
|
| Self::Sized
|
||||||
| Self::Enum
|
| Self::Enum
|
||||||
|
|
@ -1282,6 +1293,8 @@ impl<'db> KnownClass {
|
||||||
| Self::Classmethod
|
| Self::Classmethod
|
||||||
| Self::TypeVar
|
| Self::TypeVar
|
||||||
| Self::ParamSpec
|
| Self::ParamSpec
|
||||||
|
| Self::ParamSpecArgs
|
||||||
|
| Self::ParamSpecKwargs
|
||||||
| Self::TypeVarTuple
|
| Self::TypeVarTuple
|
||||||
| Self::Sized
|
| Self::Sized
|
||||||
| Self::Enum
|
| Self::Enum
|
||||||
|
|
@ -1328,6 +1341,8 @@ impl<'db> KnownClass {
|
||||||
"TypeAliasType" => Self::TypeAliasType,
|
"TypeAliasType" => Self::TypeAliasType,
|
||||||
"TypeVar" => Self::TypeVar,
|
"TypeVar" => Self::TypeVar,
|
||||||
"ParamSpec" => Self::ParamSpec,
|
"ParamSpec" => Self::ParamSpec,
|
||||||
|
"ParamSpecArgs" => Self::ParamSpecArgs,
|
||||||
|
"ParamSpecKwargs" => Self::ParamSpecKwargs,
|
||||||
"TypeVarTuple" => Self::TypeVarTuple,
|
"TypeVarTuple" => Self::TypeVarTuple,
|
||||||
"ChainMap" => Self::ChainMap,
|
"ChainMap" => Self::ChainMap,
|
||||||
"Counter" => Self::Counter,
|
"Counter" => Self::Counter,
|
||||||
|
|
@ -1405,6 +1420,8 @@ impl<'db> KnownClass {
|
||||||
| Self::NoDefaultType
|
| Self::NoDefaultType
|
||||||
| Self::SupportsIndex
|
| Self::SupportsIndex
|
||||||
| Self::ParamSpec
|
| Self::ParamSpec
|
||||||
|
| Self::ParamSpecArgs
|
||||||
|
| Self::ParamSpecKwargs
|
||||||
| Self::TypeVarTuple
|
| Self::TypeVarTuple
|
||||||
| Self::Sized
|
| Self::Sized
|
||||||
| Self::NewType => matches!(module, KnownModule::Typing | KnownModule::TypingExtensions),
|
| Self::NewType => matches!(module, KnownModule::Typing | KnownModule::TypingExtensions),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue