mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +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 {
|
||||
KnownInstanceType::TypeAliasType(alias) => Ok(Type::TypeAlias(*alias)),
|
||||
KnownInstanceType::TypeVar(typevar) => {
|
||||
let module = parsed_module(db, scope_id.file(db)).load(db);
|
||||
let index = semantic_index(db, scope_id.file(db));
|
||||
Ok(bind_typevar(
|
||||
db,
|
||||
&module,
|
||||
index,
|
||||
scope_id.file_scope_id(db),
|
||||
typevar_binding_context,
|
||||
|
@ -5709,7 +5707,6 @@ impl<'db> Type<'db> {
|
|||
.build()),
|
||||
|
||||
SpecialFormType::TypingSelf => {
|
||||
let module = parsed_module(db, scope_id.file(db)).load(db);
|
||||
let index = semantic_index(db, scope_id.file(db));
|
||||
let Some(class) = nearest_enclosing_class(db, index, scope_id) else {
|
||||
return Err(InvalidTypeExpressionError {
|
||||
|
@ -5747,7 +5744,6 @@ impl<'db> Type<'db> {
|
|||
);
|
||||
Ok(bind_typevar(
|
||||
db,
|
||||
&module,
|
||||
index,
|
||||
scope_id.file_scope_id(db),
|
||||
typevar_binding_context,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use crate::types::constraints::ConstraintSet;
|
||||
|
||||
use itertools::Itertools;
|
||||
use ruff_db::parsed::ParsedModuleRef;
|
||||
use ruff_python_ast as ast;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
|
@ -26,7 +25,6 @@ use crate::{Db, FxOrderSet};
|
|||
/// scope.
|
||||
fn enclosing_generic_contexts<'db>(
|
||||
db: &'db dyn Db,
|
||||
module: &ParsedModuleRef,
|
||||
index: &SemanticIndex<'db>,
|
||||
scope: FileScopeId,
|
||||
) -> impl Iterator<Item = GenericContext<'db>> {
|
||||
|
@ -34,13 +32,13 @@ fn enclosing_generic_contexts<'db>(
|
|||
.ancestor_scopes(scope)
|
||||
.filter_map(|(_, ancestor_scope)| match ancestor_scope.node() {
|
||||
NodeWithScopeKind::Class(class) => {
|
||||
let definition = index.expect_single_definition(class.node(module));
|
||||
let definition = index.expect_single_definition(class);
|
||||
binding_type(db, definition)
|
||||
.into_class_literal()?
|
||||
.generic_context(db)
|
||||
}
|
||||
NodeWithScopeKind::Function(function) => {
|
||||
let definition = index.expect_single_definition(function.node(module));
|
||||
let definition = index.expect_single_definition(function);
|
||||
infer_definition_types(db, definition)
|
||||
.undecorated_type()
|
||||
.expect("function should have undecorated type")
|
||||
|
@ -49,7 +47,7 @@ fn enclosing_generic_contexts<'db>(
|
|||
.generic_context
|
||||
}
|
||||
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)
|
||||
.into_type_alias()?
|
||||
.into_pep_695_type_alias()?
|
||||
|
@ -75,7 +73,6 @@ fn enclosing_generic_contexts<'db>(
|
|||
/// bind the typevar with that new binding context.
|
||||
pub(crate) fn bind_typevar<'db>(
|
||||
db: &'db dyn Db,
|
||||
module: &ParsedModuleRef,
|
||||
index: &SemanticIndex<'db>,
|
||||
containing_scope: FileScopeId,
|
||||
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() {
|
||||
if outer.kind().is_class() {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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))
|
||||
.or_else(|| {
|
||||
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 {
|
||||
bind_typevar(
|
||||
self.db(),
|
||||
self.module(),
|
||||
self.index,
|
||||
self.scope().file_scope_id(self.db()),
|
||||
self.typevar_binding_context,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue