Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions crates/ty_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -5747,7 +5744,6 @@ impl<'db> Type<'db> {
);
Ok(bind_typevar(
db,
&module,
index,
scope_id.file_scope_id(db),
typevar_binding_context,
Expand Down
13 changes: 5 additions & 8 deletions crates/ty_python_semantic/src/types/generics.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -26,21 +25,20 @@ 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>> {
index
.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")
Expand All @@ -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()?
Expand All @@ -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>>,
Expand All @@ -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| {
Expand Down
1 change: 0 additions & 1 deletion crates/ty_python_semantic/src/types/infer/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading