brokk_bifrost_python/
adapter.rs1use brokk_bifrost_core::analyzer::cognitive_complexity;
9use std::sync::LazyLock;
10
11use crate::declarations::python_is_decorated_function_boundary;
12
13pub const PYTHON_FILE_EXTENSION: &str = "py";
14
15pub static PYTHON_COGNITIVE_CONFIG: LazyLock<cognitive_complexity::Config> =
18 LazyLock::new(|| cognitive_complexity::Config {
19 if_types: &["if_statement"],
20 alternate_if_types: &["elif_clause"],
21 loop_types: &["for_statement", "while_statement"],
22 catch_types: &["except_clause"],
23 conditional_types: &["conditional_expression"],
24 case_types: &["case_clause"],
25 binary_types: &["boolean_operator"],
26 logical_operators: &["and", "or"],
27 named_function_boundary_types: &["function_definition"],
28 anonymous_function_types: &["lambda"],
29 named_function_boundary_predicate: Some(python_is_decorated_function_boundary),
30 ..cognitive_complexity::Config::empty()
31 });
32
33pub fn python_extract_call_receiver(reference: &str) -> Option<String> {
34 let trimmed = reference.trim();
35 let before_args = trimmed
36 .split_once('(')
37 .map(|(head, _)| head)
38 .unwrap_or(trimmed);
39 before_args
40 .rsplit_once('.')
41 .map(|(receiver, _)| receiver.to_string())
42}