mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
[ty] Fix descriptor lookups for most types that overlap with None
(#19120)
Some checks failed
CI / Determine changes (push) Has been cancelled
CI / cargo fmt (push) Has been cancelled
CI / cargo build (release) (push) Has been cancelled
CI / python package (push) Has been cancelled
CI / pre-commit (push) Has been cancelled
CI / mkdocs (push) Has been cancelled
[ty Playground] Release / publish (push) Has been cancelled
CI / cargo clippy (push) Has been cancelled
CI / cargo test (linux) (push) Has been cancelled
CI / cargo test (linux, release) (push) Has been cancelled
CI / cargo test (windows) (push) Has been cancelled
CI / cargo test (wasm) (push) Has been cancelled
CI / cargo build (msrv) (push) Has been cancelled
CI / cargo fuzz build (push) Has been cancelled
CI / fuzz parser (push) Has been cancelled
CI / test scripts (push) Has been cancelled
CI / ecosystem (push) Has been cancelled
CI / Fuzz for new ty panics (push) Has been cancelled
CI / cargo shear (push) Has been cancelled
CI / formatter instabilities and black similarity (push) Has been cancelled
CI / test ruff-lsp (push) Has been cancelled
CI / check playground (push) Has been cancelled
CI / benchmarks-instrumented (push) Has been cancelled
CI / benchmarks-walltime (push) Has been cancelled
Some checks failed
CI / Determine changes (push) Has been cancelled
CI / cargo fmt (push) Has been cancelled
CI / cargo build (release) (push) Has been cancelled
CI / python package (push) Has been cancelled
CI / pre-commit (push) Has been cancelled
CI / mkdocs (push) Has been cancelled
[ty Playground] Release / publish (push) Has been cancelled
CI / cargo clippy (push) Has been cancelled
CI / cargo test (linux) (push) Has been cancelled
CI / cargo test (linux, release) (push) Has been cancelled
CI / cargo test (windows) (push) Has been cancelled
CI / cargo test (wasm) (push) Has been cancelled
CI / cargo build (msrv) (push) Has been cancelled
CI / cargo fuzz build (push) Has been cancelled
CI / fuzz parser (push) Has been cancelled
CI / test scripts (push) Has been cancelled
CI / ecosystem (push) Has been cancelled
CI / Fuzz for new ty panics (push) Has been cancelled
CI / cargo shear (push) Has been cancelled
CI / formatter instabilities and black similarity (push) Has been cancelled
CI / test ruff-lsp (push) Has been cancelled
CI / check playground (push) Has been cancelled
CI / benchmarks-instrumented (push) Has been cancelled
CI / benchmarks-walltime (push) Has been cancelled
This commit is contained in:
parent
44f2f77748
commit
08d8819c8a
4 changed files with 44 additions and 15 deletions
|
@ -3069,10 +3069,6 @@ impl<'db> Type<'db> {
|
|||
|
||||
Type::ModuleLiteral(module) => module.static_member(db, name_str).into(),
|
||||
|
||||
Type::AlwaysFalsy | Type::AlwaysTruthy => {
|
||||
self.class_member_with_policy(db, name, policy)
|
||||
}
|
||||
|
||||
_ if policy.no_instance_fallback() => self.invoke_descriptor_protocol(
|
||||
db,
|
||||
name_str,
|
||||
|
@ -3094,6 +3090,8 @@ impl<'db> Type<'db> {
|
|||
| Type::KnownInstance(..)
|
||||
| Type::PropertyInstance(..)
|
||||
| Type::FunctionLiteral(..)
|
||||
| Type::AlwaysTruthy
|
||||
| Type::AlwaysFalsy
|
||||
| Type::TypeIs(..) => {
|
||||
let fallback = self.instance_member(db, name_str);
|
||||
|
||||
|
@ -3533,7 +3531,6 @@ impl<'db> Type<'db> {
|
|||
// For `builtins.property.__get__`, we use the same signature. The return types are not
|
||||
// specified yet, they will be dynamically added in `Bindings::evaluate_known_cases`.
|
||||
|
||||
let not_none = Type::none(db).negate(db);
|
||||
CallableBinding::from_overloads(
|
||||
self,
|
||||
[
|
||||
|
@ -3549,7 +3546,7 @@ impl<'db> Type<'db> {
|
|||
Signature::new(
|
||||
Parameters::new([
|
||||
Parameter::positional_only(Some(Name::new_static("instance")))
|
||||
.with_annotated_type(not_none),
|
||||
.with_annotated_type(Type::object(db)),
|
||||
Parameter::positional_only(Some(Name::new_static("owner")))
|
||||
.with_annotated_type(UnionType::from_elements(
|
||||
db,
|
||||
|
@ -3575,7 +3572,6 @@ impl<'db> Type<'db> {
|
|||
// TODO: Consider merging this signature with the one in the previous match clause,
|
||||
// since the previous one is just this signature with the `self` parameters
|
||||
// removed.
|
||||
let not_none = Type::none(db).negate(db);
|
||||
let descriptor = match kind {
|
||||
WrapperDescriptorKind::FunctionTypeDunderGet => {
|
||||
KnownClass::FunctionType.to_instance(db)
|
||||
|
@ -3606,7 +3602,7 @@ impl<'db> Type<'db> {
|
|||
Parameter::positional_only(Some(Name::new_static("self")))
|
||||
.with_annotated_type(descriptor),
|
||||
Parameter::positional_only(Some(Name::new_static("instance")))
|
||||
.with_annotated_type(not_none),
|
||||
.with_annotated_type(Type::object(db)),
|
||||
Parameter::positional_only(Some(Name::new_static("owner")))
|
||||
.with_annotated_type(UnionType::from_elements(
|
||||
db,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue