mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:21 +00:00
[ty] Remove unnecessary parsed_module()
calls (#20630)
This commit is contained in:
parent
00c8851ef8
commit
1d3e4a9153
3 changed files with 5 additions and 13 deletions
|
@ -5632,11 +5632,9 @@ impl<'db> Type<'db> {
|
||||||
Type::KnownInstance(known_instance) => match known_instance {
|
Type::KnownInstance(known_instance) => match known_instance {
|
||||||
KnownInstanceType::TypeAliasType(alias) => Ok(Type::TypeAlias(*alias)),
|
KnownInstanceType::TypeAliasType(alias) => Ok(Type::TypeAlias(*alias)),
|
||||||
KnownInstanceType::TypeVar(typevar) => {
|
KnownInstanceType::TypeVar(typevar) => {
|
||||||
let module = parsed_module(db, scope_id.file(db)).load(db);
|
|
||||||
let index = semantic_index(db, scope_id.file(db));
|
let index = semantic_index(db, scope_id.file(db));
|
||||||
Ok(bind_typevar(
|
Ok(bind_typevar(
|
||||||
db,
|
db,
|
||||||
&module,
|
|
||||||
index,
|
index,
|
||||||
scope_id.file_scope_id(db),
|
scope_id.file_scope_id(db),
|
||||||
typevar_binding_context,
|
typevar_binding_context,
|
||||||
|
@ -5709,7 +5707,6 @@ impl<'db> Type<'db> {
|
||||||
.build()),
|
.build()),
|
||||||
|
|
||||||
SpecialFormType::TypingSelf => {
|
SpecialFormType::TypingSelf => {
|
||||||
let module = parsed_module(db, scope_id.file(db)).load(db);
|
|
||||||
let index = semantic_index(db, scope_id.file(db));
|
let index = semantic_index(db, scope_id.file(db));
|
||||||
let Some(class) = nearest_enclosing_class(db, index, scope_id) else {
|
let Some(class) = nearest_enclosing_class(db, index, scope_id) else {
|
||||||
return Err(InvalidTypeExpressionError {
|
return Err(InvalidTypeExpressionError {
|
||||||
|
@ -5747,7 +5744,6 @@ impl<'db> Type<'db> {
|
||||||
);
|
);
|
||||||
Ok(bind_typevar(
|
Ok(bind_typevar(
|
||||||
db,
|
db,
|
||||||
&module,
|
|
||||||
index,
|
index,
|
||||||
scope_id.file_scope_id(db),
|
scope_id.file_scope_id(db),
|
||||||
typevar_binding_context,
|
typevar_binding_context,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::types::constraints::ConstraintSet;
|
use crate::types::constraints::ConstraintSet;
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use ruff_db::parsed::ParsedModuleRef;
|
|
||||||
use ruff_python_ast as ast;
|
use ruff_python_ast as ast;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
|
@ -26,7 +25,6 @@ use crate::{Db, FxOrderSet};
|
||||||
/// scope.
|
/// scope.
|
||||||
fn enclosing_generic_contexts<'db>(
|
fn enclosing_generic_contexts<'db>(
|
||||||
db: &'db dyn Db,
|
db: &'db dyn Db,
|
||||||
module: &ParsedModuleRef,
|
|
||||||
index: &SemanticIndex<'db>,
|
index: &SemanticIndex<'db>,
|
||||||
scope: FileScopeId,
|
scope: FileScopeId,
|
||||||
) -> impl Iterator<Item = GenericContext<'db>> {
|
) -> impl Iterator<Item = GenericContext<'db>> {
|
||||||
|
@ -34,13 +32,13 @@ fn enclosing_generic_contexts<'db>(
|
||||||
.ancestor_scopes(scope)
|
.ancestor_scopes(scope)
|
||||||
.filter_map(|(_, ancestor_scope)| match ancestor_scope.node() {
|
.filter_map(|(_, ancestor_scope)| match ancestor_scope.node() {
|
||||||
NodeWithScopeKind::Class(class) => {
|
NodeWithScopeKind::Class(class) => {
|
||||||
let definition = index.expect_single_definition(class.node(module));
|
let definition = index.expect_single_definition(class);
|
||||||
binding_type(db, definition)
|
binding_type(db, definition)
|
||||||
.into_class_literal()?
|
.into_class_literal()?
|
||||||
.generic_context(db)
|
.generic_context(db)
|
||||||
}
|
}
|
||||||
NodeWithScopeKind::Function(function) => {
|
NodeWithScopeKind::Function(function) => {
|
||||||
let definition = index.expect_single_definition(function.node(module));
|
let definition = index.expect_single_definition(function);
|
||||||
infer_definition_types(db, definition)
|
infer_definition_types(db, definition)
|
||||||
.undecorated_type()
|
.undecorated_type()
|
||||||
.expect("function should have undecorated type")
|
.expect("function should have undecorated type")
|
||||||
|
@ -49,7 +47,7 @@ fn enclosing_generic_contexts<'db>(
|
||||||
.generic_context
|
.generic_context
|
||||||
}
|
}
|
||||||
NodeWithScopeKind::TypeAlias(type_alias) => {
|
NodeWithScopeKind::TypeAlias(type_alias) => {
|
||||||
let definition = index.expect_single_definition(type_alias.node(module));
|
let definition = index.expect_single_definition(type_alias);
|
||||||
binding_type(db, definition)
|
binding_type(db, definition)
|
||||||
.into_type_alias()?
|
.into_type_alias()?
|
||||||
.into_pep_695_type_alias()?
|
.into_pep_695_type_alias()?
|
||||||
|
@ -75,7 +73,6 @@ fn enclosing_generic_contexts<'db>(
|
||||||
/// bind the typevar with that new binding context.
|
/// bind the typevar with that new binding context.
|
||||||
pub(crate) fn bind_typevar<'db>(
|
pub(crate) fn bind_typevar<'db>(
|
||||||
db: &'db dyn Db,
|
db: &'db dyn Db,
|
||||||
module: &ParsedModuleRef,
|
|
||||||
index: &SemanticIndex<'db>,
|
index: &SemanticIndex<'db>,
|
||||||
containing_scope: FileScopeId,
|
containing_scope: FileScopeId,
|
||||||
typevar_binding_context: Option<Definition<'db>>,
|
typevar_binding_context: Option<Definition<'db>>,
|
||||||
|
@ -86,13 +83,13 @@ pub(crate) fn bind_typevar<'db>(
|
||||||
for ((_, inner), (_, outer)) in index.ancestor_scopes(containing_scope).tuple_windows() {
|
for ((_, inner), (_, outer)) in index.ancestor_scopes(containing_scope).tuple_windows() {
|
||||||
if outer.kind().is_class() {
|
if outer.kind().is_class() {
|
||||||
if let NodeWithScopeKind::Function(function) = inner.node() {
|
if let NodeWithScopeKind::Function(function) = inner.node() {
|
||||||
let definition = index.expect_single_definition(function.node(module));
|
let definition = index.expect_single_definition(function);
|
||||||
return Some(typevar.with_binding_context(db, definition));
|
return Some(typevar.with_binding_context(db, definition));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enclosing_generic_contexts(db, module, index, containing_scope)
|
enclosing_generic_contexts(db, index, containing_scope)
|
||||||
.find_map(|enclosing_context| enclosing_context.binds_typevar(db, typevar))
|
.find_map(|enclosing_context| enclosing_context.binds_typevar(db, typevar))
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
typevar_binding_context.map(|typevar_binding_context| {
|
typevar_binding_context.map(|typevar_binding_context| {
|
||||||
|
|
|
@ -8978,7 +8978,6 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
||||||
if let Type::KnownInstance(KnownInstanceType::TypeVar(typevar)) = typevar {
|
if let Type::KnownInstance(KnownInstanceType::TypeVar(typevar)) = typevar {
|
||||||
bind_typevar(
|
bind_typevar(
|
||||||
self.db(),
|
self.db(),
|
||||||
self.module(),
|
|
||||||
self.index,
|
self.index,
|
||||||
self.scope().file_scope_id(self.db()),
|
self.scope().file_scope_id(self.db()),
|
||||||
self.typevar_binding_context,
|
self.typevar_binding_context,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue