brokk-bifrost-python 0.15.2

Python language knowledge for brokk-bifrost: module identity, declarations, imports, and usage-graph resolution
Documentation
//! Analyzer-independent language rules.

use brokk_bifrost_core::analyzer::CodeUnit;
use brokk_bifrost_core::analyzer::Language;
use brokk_bifrost_core::analyzer::ProjectFile;
use brokk_bifrost_core::analyzer::language_knowledge::LanguageKnowledge;
use brokk_bifrost_core::analyzer::language_knowledge::ParserFlavor;
use brokk_bifrost_core::analyzer::project::Project;
use brokk_bifrost_core::analyzer::structural::spec::StructuralSpec;

/// Python syntax and static language rules.
pub struct PythonKnowledge;

impl LanguageKnowledge for PythonKnowledge {
    fn unmarked_member_stores(
        &self,
    ) -> brokk_bifrost_core::analyzer::language_knowledge::UnmarkedMemberStores {
        brokk_bifrost_core::analyzer::language_knowledge::UnmarkedMemberStores::Followable
    }

    fn declared_type_is_referent_immutable(&self, _canonical_type: &str) -> bool {
        false
    }

    // Applicability decides whether a Python call returns or raises, not which
    // declaration its callee reference names.
    fn call_applicability_may_select_callee(&self) -> bool {
        false
    }

    // Invocation validity does not choose a declaration's modeled result type.
    // Native typing.overload selection is not modeled; decorated values retain
    // their existing unknown-value evidence instead of overload alternatives.
    fn callable_result_is_applicability_independent(&self) -> bool {
        true
    }

    fn external_callee_expansion_requires_receiver_binding(&self) -> bool {
        true
    }

    fn exact_external_call_keeps_import_boundary(&self) -> bool {
        true
    }

    fn model_declarations_project_runtime_values(&self) -> bool {
        true
    }

    fn model_declarations_supply_runtime_bases(&self) -> bool {
        true
    }

    fn intrinsic_owners_use_source_member_rules(&self) -> bool {
        true
    }

    fn qualified_type_lookups_use_value_namespace(&self) -> bool {
        true
    }

    fn callable_expression_type_gap_is_value_only(&self) -> bool {
        true
    }

    fn owned_members_are_not_lexically_scoped(&self) -> bool {
        true
    }

    fn reassignments_are_one_declaration(&self) -> bool {
        true
    }

    fn keyed_property_reads_container_element(&self) -> bool {
        true
    }

    fn language(&self) -> Language {
        Language::Python
    }

    fn path_synthetic_module_unit(
        &self,
        project: &dyn Project,
        file: &ProjectFile,
    ) -> Option<CodeUnit> {
        use crate::declarations::module_code_unit;
        module_code_unit(project, file)
    }

    fn parser_language(&self, _flavor: ParserFlavor) -> tree_sitter::Language {
        tree_sitter_python::LANGUAGE.into()
    }

    fn structural_spec(&self) -> &'static dyn StructuralSpec {
        &crate::structural::PYTHON_STRUCTURAL_SPEC
    }

    fn highlight_query(&self) -> Option<&'static str> {
        Some(tree_sitter_python::HIGHLIGHTS_QUERY)
    }
}