(statement: &str)
| 402 | } |
| 403 | |
| 404 | fn extract_python_import_binding_info(statement: &str) -> Option<(String, Vec<ImportBinding>)> { |
| 405 | if let Some(import_body) = statement.strip_prefix("from ") { |
| 406 | let (specifier, bindings_part) = import_body.split_once(" import ")?; |
| 407 | let specifier = specifier.trim(); |
| 408 | if specifier.is_empty() { |
| 409 | return None; |
| 410 | } |
| 411 | let bindings = parse_python_import_bindings(bindings_part)?; |
| 412 | return Some((specifier.to_string(), bindings)); |
| 413 | } |
| 414 | |
| 415 | if statement.contains(" from ") |
| 416 | || statement.contains('"') |
| 417 | || statement.contains('\'') |
| 418 | || statement.contains('{') |
| 419 | || statement.contains('*') |
| 420 | { |
| 421 | return None; |
| 422 | } |
| 423 | |
| 424 | let import_body = statement.strip_prefix("import ")?; |
| 425 | let mut bindings = Vec::new(); |
| 426 | for part in import_body.split(',') { |
| 427 | let part = part.trim(); |
| 428 | if part.is_empty() { |
| 429 | continue; |
| 430 | } |
| 431 | let (_, local_name) = part |
| 432 | .split_once(" as ") |
| 433 | .map(|(source, alias)| (source.trim(), alias.trim())) |
| 434 | .unwrap_or((part, part)); |
| 435 | if local_name.is_empty() { |
| 436 | continue; |
| 437 | } |
| 438 | bindings.push(ImportBinding { |
| 439 | local_name: local_name.to_string(), |
| 440 | source_symbol: None, |
| 441 | }); |
| 442 | } |
| 443 | if bindings.is_empty() { |
| 444 | None |
| 445 | } else { |
| 446 | Some((import_body.split_whitespace().next()?.to_string(), bindings)) |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | fn parse_python_import_bindings(bindings_part: &str) -> Option<Vec<ImportBinding>> { |
| 451 | let bindings_part = bindings_part |
no test coverage detected
searching dependent graphs…