Skip to content
Open
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
1 change: 1 addition & 0 deletions crates/ty_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ mod variance;
mod visitor;

mod definition;
pub(crate) mod definition_resolution;
#[cfg(test)]
mod property_tests;
mod subscript;
Expand Down
20 changes: 13 additions & 7 deletions crates/ty_python_semantic/src/types/dedicated/pydantic.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
use crate::ProgramEnvironment;
use char_str::CharStr;
use ruff_db::parsed::parsed_module;
use ruff_python_ast::{ArgOrKeyword, Arguments, Expr, ExprCall, ExprDict, Keyword, name::Name};
use ruff_python_ast::{
ArgOrKeyword, Arguments, Expr, ExprCall, ExprDict, ExprRef, Keyword, name::Name,
};
use rustc_hash::FxHashSet;
use ty_module_resolver::{KnownModule, file_to_module};
use ty_python_core::{
definition::{Definition, DefinitionKind},
place_table, use_def_map,
place_table, semantic_index, use_def_map,
};

use crate::Db;
use crate::diagnostic::format_enumeration;
use crate::place::{DefinedPlace, Definedness, Place, Provenance, known_module_symbol};
use crate::reachability::DeclarationsIteratorExtension;
use crate::types::call::Bindings;
use crate::types::class::CodeGeneratorKind;
use crate::types::context::InferContext;
use crate::types::definition_resolution::{ImportAliasResolution, definitions_for_name};
use crate::types::diagnostic::PYDANTIC_DISCARDED_EXTRA_ARGUMENT;
use crate::types::ide_support::{ImportAliasResolution, definitions_for_name};
use crate::types::infer::function_known_decorators;
use crate::types::known_instance::FieldInstance;
use crate::types::member::class_member;
Expand All @@ -26,7 +29,6 @@ use crate::types::{
KnownInstanceType, KnownUnion, Parameter, Specialization, StaticClassLiteral, Type, UnionType,
definition_expression_type,
};
use crate::{Db, SemanticModel};

/// Pydantic treats underscore-prefixed annotations as private instance attributes.
pub(in crate::types) fn is_private_attribute(name: &str) -> bool {
Expand Down Expand Up @@ -171,11 +173,15 @@ impl<'db> FieldMetadata<'db> {
// using `StrictInt = Annotated[int, Strict()]`. Since we don't retain the `Annotated`
// metadata, we need to follow the alias back to its definition and parse the metadata
// from there.
let model = SemanticModel::new(db, definition.program_file(db));
let file = definition.program_file(db);
let index = semantic_index(db, file);
let Some(scope) = index.try_expression_scope_id(&ExprRef::Name(name)) else {
return;
};
let Some(alias_definition) = definitions_for_name(
&model,
db,
scope.to_scope_id(db, file),
name.id.as_str(),
name.into(),
ImportAliasResolution::ResolveAliases,
)
.into_iter()
Expand Down
Loading
Loading