[ty] Export some stuff from ty_python_semantic

We're going to want to use this outside of `ty_python_semantic`.
Specifically, in `ty_ide`.
This commit is contained in:
Andrew Gallant 2025-09-16 12:46:42 -04:00 committed by Andrew Gallant
parent 61a49c89eb
commit cf16fc4aa4
6 changed files with 25 additions and 16 deletions

View file

@ -7,7 +7,7 @@ use std::hash::BuildHasherDefault;
use crate::lint::{LintRegistry, LintRegistryBuilder};
use crate::suppression::{INVALID_IGNORE_COMMENT, UNKNOWN_RULE, UNUSED_IGNORE_COMMENT};
pub use db::Db;
pub use module_name::ModuleName;
pub use module_name::{ModuleName, ModuleNameResolutionError};
pub use module_resolver::{
Module, SearchPath, SearchPathValidationError, SearchPaths, all_modules, list_modules,
resolve_module, resolve_real_module, system_module_search_paths,

View file

@ -273,7 +273,14 @@ impl ModuleName {
std::iter::successors(Some(self.clone()), Self::parent)
}
pub(crate) fn from_import_statement<'db>(
/// Extracts a module name from the AST of a `from <module> import ...`
/// statement.
///
/// `importing_file` must be the [`File`] that contains the import
/// statement.
///
/// This handles relative import statements.
pub fn from_import_statement<'db>(
db: &'db dyn Db,
importing_file: File,
node: &'db ast::StmtImportFrom,
@ -372,7 +379,7 @@ fn relative_module_name(
/// Various ways in which resolving a [`ModuleName`]
/// from an [`ast::StmtImport`] or [`ast::StmtImportFrom`] node might fail
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub(crate) enum ModuleNameResolutionError {
pub enum ModuleNameResolutionError {
/// The import statement has invalid syntax
InvalidSyntax,

View file

@ -38,7 +38,7 @@ pub struct Definition<'db> {
#[no_eq]
#[returns(ref)]
#[tracked]
pub(crate) kind: DefinitionKind<'db>,
pub kind: DefinitionKind<'db>,
/// This is a dedicated field to avoid accessing `kind` to compute this value.
pub(crate) is_reexported: bool,
@ -876,7 +876,7 @@ pub struct StarImportDefinitionKind {
}
impl StarImportDefinitionKind {
pub(crate) fn import<'ast>(&self, module: &'ast ParsedModuleRef) -> &'ast ast::StmtImportFrom {
pub fn import<'ast>(&self, module: &'ast ParsedModuleRef) -> &'ast ast::StmtImportFrom {
self.node.node(module)
}
@ -960,7 +960,7 @@ pub struct ImportDefinitionKind {
}
impl ImportDefinitionKind {
pub(crate) fn import<'ast>(&self, module: &'ast ParsedModuleRef) -> &'ast ast::StmtImport {
pub fn import<'ast>(&self, module: &'ast ParsedModuleRef) -> &'ast ast::StmtImport {
self.node.node(module)
}
@ -981,7 +981,7 @@ pub struct ImportFromDefinitionKind {
}
impl ImportFromDefinitionKind {
pub(crate) fn import<'ast>(&self, module: &'ast ParsedModuleRef) -> &'ast ast::StmtImportFrom {
pub fn import<'ast>(&self, module: &'ast ParsedModuleRef) -> &'ast ast::StmtImportFrom {
self.node.node(module)
}

View file

@ -670,7 +670,7 @@ pub(crate) struct EnclosingSnapshotKey {
/// new binding.
type EnclosingSnapshots = IndexVec<ScopedEnclosingSnapshotId, EnclosingSnapshot>;
#[derive(Debug)]
#[derive(Clone, Debug)]
pub(crate) struct BindingWithConstraintsIterator<'map, 'db> {
all_definitions: &'map IndexVec<ScopedDefinitionId, DefinitionState<'db>>,
pub(crate) predicates: &'map Predicates<'db>,

View file

@ -19,7 +19,8 @@ use ruff_text_size::{Ranged, TextRange};
use type_ordering::union_or_intersection_elements_ordering;
pub(crate) use self::builder::{IntersectionBuilder, UnionBuilder};
pub(crate) use self::cyclic::{CycleDetector, PairVisitor, TypeTransformer};
pub use self::cyclic::CycleDetector;
pub(crate) use self::cyclic::{PairVisitor, TypeTransformer};
pub use self::diagnostic::TypeCheckDiagnostics;
pub(crate) use self::diagnostic::register_lints;
pub(crate) use self::infer::{
@ -54,9 +55,10 @@ use crate::types::generics::{
walk_partial_specialization, walk_specialization,
};
pub use crate::types::ide_support::{
CallSignatureDetails, Member, all_members, call_signature_details, definition_kind_for_name,
definitions_for_attribute, definitions_for_imported_symbol, definitions_for_keyword_argument,
definitions_for_name, find_active_signature_from_details, inlay_hint_function_argument_details,
CallSignatureDetails, Member, MemberWithDefinition, all_members, call_signature_details,
definition_kind_for_name, definitions_for_attribute, definitions_for_imported_symbol,
definitions_for_keyword_argument, definitions_for_name, find_active_signature_from_details,
inlay_hint_function_argument_details,
};
use crate::types::infer::infer_unpack_types;
use crate::types::mro::{Mro, MroError, MroIterator};
@ -9953,7 +9955,7 @@ impl<'db> TypeAliasType<'db> {
}
}
pub(crate) fn value_type(self, db: &'db dyn Db) -> Type<'db> {
pub fn value_type(self, db: &'db dyn Db) -> Type<'db> {
match self {
TypeAliasType::PEP695(type_alias) => type_alias.value_type(db),
TypeAliasType::ManualPEP695(type_alias) => type_alias.value(db),

View file

@ -44,7 +44,7 @@ impl<Tag> Default for TypeTransformer<'_, Tag> {
pub(crate) type PairVisitor<'db, Tag, C> = CycleDetector<Tag, (Type<'db>, Type<'db>), C>;
#[derive(Debug)]
pub(crate) struct CycleDetector<Tag, T, R> {
pub struct CycleDetector<Tag, T, R> {
/// If the type we're visiting is present in `seen`, it indicates that we've hit a cycle (due
/// to a recursive type); we need to immediately short circuit the whole operation and return
/// the fallback value. That's why we pop items off the end of `seen` after we've visited them.
@ -64,7 +64,7 @@ pub(crate) struct CycleDetector<Tag, T, R> {
}
impl<Tag, T: Hash + Eq + Clone, R: Clone> CycleDetector<Tag, T, R> {
pub(crate) fn new(fallback: R) -> Self {
pub fn new(fallback: R) -> Self {
CycleDetector {
seen: RefCell::new(FxIndexSet::default()),
cache: RefCell::new(FxHashMap::default()),
@ -73,7 +73,7 @@ impl<Tag, T: Hash + Eq + Clone, R: Clone> CycleDetector<Tag, T, R> {
}
}
pub(crate) fn visit(&self, item: T, func: impl FnOnce() -> R) -> R {
pub fn visit(&self, item: T, func: impl FnOnce() -> R) -> R {
if let Some(val) = self.cache.borrow().get(&item) {
return val.clone();
}