tree-sitter-analyzer 1.5.0__py3-none-any.whl → 1.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of tree-sitter-analyzer might be problematic. Click here for more details.

@@ -1,6 +1,11 @@
1
1
  #!/usr/bin/env python3
2
2
  """
3
- Python Tree-sitter queries for code analysis.
3
+ Python Language Queries
4
+
5
+ Comprehensive Tree-sitter queries for Python language constructs.
6
+ Covers functions, classes, variables, imports, decorators, async/await,
7
+ type hints, and modern Python features.
8
+ Equivalent to JavaScript query coverage for consistent language support.
4
9
  """
5
10
 
6
11
  # Function definitions
@@ -206,64 +211,608 @@ MODERN_PATTERNS = """
206
211
  right: (_) @walrus.value) @assignment.walrus
207
212
  """
208
213
 
209
- # All queries combined
210
- ALL_QUERIES = {
211
- "functions": {
212
- "query": FUNCTIONS,
213
- "description": "Search all function definitions (including async)",
214
- },
215
- "classes": {"query": CLASSES, "description": "Search all class definitions"},
216
- "imports": {"query": IMPORTS, "description": "Search all import statements"},
217
- "variables": {"query": VARIABLES, "description": "Search all variable assignments"},
218
- "decorators": {"query": DECORATORS, "description": "Search all decorators"},
219
- "methods": {
220
- "query": METHODS,
221
- "description": "Search all method definitions within classes",
222
- },
223
- "exceptions": {
224
- "query": EXCEPTIONS,
225
- "description": "Search exception handling and raise statements",
226
- },
227
- "comprehensions": {
228
- "query": COMPREHENSIONS,
229
- "description": "Search list, dictionary, and set comprehensions",
230
- },
231
- "comments": {"query": COMMENTS, "description": "Search comments and docstrings"},
232
- "type_hints": {
233
- "query": TYPE_HINTS,
234
- "description": "Search type hints and annotations",
235
- },
236
- "async_patterns": {
237
- "query": ASYNC_PATTERNS,
238
- "description": "Search async/await patterns",
239
- },
240
- "string_formatting": {
241
- "query": STRING_FORMATTING,
242
- "description": "Search f-strings and string formatting",
243
- },
244
- "context_managers": {
245
- "query": CONTEXT_MANAGERS,
246
- "description": "Search context managers (with statements)",
247
- },
248
- "lambdas": {"query": LAMBDAS, "description": "Search lambda expressions"},
249
- "modern_patterns": {
250
- "query": MODERN_PATTERNS,
251
- "description": "Search modern Python patterns (match/case, walrus operator)",
252
- },
253
- # Convenience aliases
254
- "function_names": {
255
- "query": FUNCTIONS,
256
- "description": "Function alias - search all function definitions",
257
- },
258
- "class_names": {
259
- "query": CLASSES,
260
- "description": "Class alias - search all class definitions",
261
- },
262
- "all_declarations": {
263
- "query": FUNCTIONS + "\n\n" + CLASSES + "\n\n" + VARIABLES,
264
- "description": "Search all function, class, and variable declarations",
265
- },
214
+ # Python-specific comprehensive query library
215
+ PYTHON_QUERIES: dict[str, str] = {
216
+ # --- Basic Structure ---
217
+ "function": """
218
+ (function_definition) @function
219
+ """,
220
+ "function_definition": """
221
+ (function_definition
222
+ name: (identifier) @function_name
223
+ parameters: (parameters) @parameters
224
+ body: (block) @body) @function_definition
225
+ """,
226
+ "async_function": """
227
+ (function_definition
228
+ "async" @async_keyword
229
+ name: (identifier) @function_name
230
+ parameters: (parameters) @parameters
231
+ body: (block) @body) @async_function
232
+ """,
233
+ "method": """
234
+ (function_definition
235
+ name: (identifier) @method_name
236
+ parameters: (parameters
237
+ (identifier) @self_param
238
+ . (_)*) @method_params
239
+ body: (block) @method_body) @method_definition
240
+ """,
241
+ "lambda": """
242
+ (lambda
243
+ parameters: (lambda_parameters)? @lambda_params
244
+ body: (_) @lambda_body) @lambda_expression
245
+ """,
246
+ # --- Classes ---
247
+ "class": """
248
+ (class_definition) @class
249
+ """,
250
+ "class_definition": """
251
+ (class_definition
252
+ name: (identifier) @class_name
253
+ superclasses: (argument_list)? @superclasses
254
+ body: (block) @body) @class_definition
255
+ """,
256
+ "class_method": """
257
+ (class_definition
258
+ body: (block
259
+ (function_definition
260
+ name: (identifier) @method_name
261
+ parameters: (parameters) @parameters
262
+ body: (block) @method_body))) @class_method
263
+ """,
264
+ "constructor": """
265
+ (function_definition
266
+ name: (identifier) @constructor_name
267
+ (#match? @constructor_name "__init__")
268
+ parameters: (parameters) @parameters
269
+ body: (block) @body) @constructor
270
+ """,
271
+ "property": """
272
+ (decorated_definition
273
+ (decorator
274
+ (identifier) @decorator_name
275
+ (#match? @decorator_name "property"))
276
+ (function_definition
277
+ name: (identifier) @property_name)) @property_definition
278
+ """,
279
+ "staticmethod": """
280
+ (decorated_definition
281
+ (decorator
282
+ (identifier) @decorator_name
283
+ (#match? @decorator_name "staticmethod"))
284
+ (function_definition
285
+ name: (identifier) @method_name)) @static_method
286
+ """,
287
+ "classmethod": """
288
+ (decorated_definition
289
+ (decorator
290
+ (identifier) @decorator_name
291
+ (#match? @decorator_name "classmethod"))
292
+ (function_definition
293
+ name: (identifier) @method_name)) @class_method_decorator
294
+ """,
295
+ # --- Variables and Assignments ---
296
+ "variable": """
297
+ (assignment) @variable
298
+ """,
299
+ "assignment": """
300
+ (assignment
301
+ left: (identifier) @variable_name
302
+ right: (_) @value) @assignment
303
+ """,
304
+ "multiple_assignment": """
305
+ (assignment
306
+ left: (pattern_list) @variables
307
+ right: (_) @value) @multiple_assignment
308
+ """,
309
+ "augmented_assignment": """
310
+ (augmented_assignment
311
+ left: (identifier) @variable_name
312
+ right: (_) @value) @augmented_assignment
313
+ """,
314
+ "global_statement": """
315
+ (global_statement
316
+ (identifier) @global_var) @global_declaration
317
+ """,
318
+ "nonlocal_statement": """
319
+ (nonlocal_statement
320
+ (identifier) @nonlocal_var) @nonlocal_declaration
321
+ """,
322
+ # --- Imports ---
323
+ "import": """
324
+ (import_statement) @import
325
+ """,
326
+ "import_statement": """
327
+ (import_statement
328
+ name: (dotted_name) @import_name) @import_statement
329
+ """,
330
+ "import_from": """
331
+ (import_from_statement
332
+ module_name: (dotted_name)? @module_name
333
+ name: (dotted_name) @import_name) @import_from
334
+ """,
335
+ "import_from_list": """
336
+ (import_from_statement
337
+ module_name: (dotted_name)? @module_name
338
+ name: (import_list) @import_list) @import_from_list
339
+ """,
340
+ "aliased_import": """
341
+ (aliased_import
342
+ name: (dotted_name) @import_name
343
+ alias: (identifier) @alias) @aliased_import
344
+ """,
345
+ "import_star": """
346
+ (import_from_statement
347
+ module_name: (dotted_name) @module_name
348
+ name: (wildcard_import) @star_import) @import_star
349
+ """,
350
+ # --- Decorators ---
351
+ "decorator": """
352
+ (decorator) @decorator
353
+ """,
354
+ "decorator_simple": """
355
+ (decorator
356
+ (identifier) @decorator_name) @decorator_simple
357
+ """,
358
+ "decorator_call": """
359
+ (decorator
360
+ (call
361
+ function: (identifier) @decorator_name
362
+ arguments: (argument_list) @decorator_args)) @decorator_call
363
+ """,
364
+ "decorator_attribute": """
365
+ (decorator
366
+ (attribute
367
+ object: (identifier) @decorator_object
368
+ attribute: (identifier) @decorator_name)) @decorator_attribute
369
+ """,
370
+ "decorated_function": """
371
+ (decorated_definition
372
+ (decorator)+ @decorators
373
+ (function_definition
374
+ name: (identifier) @function_name)) @decorated_function
375
+ """,
376
+ "decorated_class": """
377
+ (decorated_definition
378
+ (decorator)+ @decorators
379
+ (class_definition
380
+ name: (identifier) @class_name)) @decorated_class
381
+ """,
382
+ # --- Control Flow ---
383
+ "if_statement": """
384
+ (if_statement
385
+ condition: (_) @condition
386
+ consequence: (block) @then_branch
387
+ alternative: (_)? @else_branch) @if_statement
388
+ """,
389
+ "for_statement": """
390
+ (for_statement
391
+ left: (_) @loop_var
392
+ right: (_) @iterable
393
+ body: (block) @body) @for_statement
394
+ """,
395
+ "while_statement": """
396
+ (while_statement
397
+ condition: (_) @condition
398
+ body: (block) @body) @while_statement
399
+ """,
400
+ "with_statement": """
401
+ (with_statement
402
+ (with_clause
403
+ (with_item
404
+ value: (_) @context_manager)) @with_clause
405
+ body: (block) @body) @with_statement
406
+ """,
407
+ "async_with": """
408
+ (async_with_statement
409
+ (with_clause
410
+ (with_item
411
+ value: (_) @context_manager)) @with_clause
412
+ body: (block) @body) @async_with_statement
413
+ """,
414
+ "async_for": """
415
+ (async_for_statement
416
+ left: (_) @loop_var
417
+ right: (_) @async_iterable
418
+ body: (block) @body) @async_for_statement
419
+ """,
420
+ # --- Exception Handling ---
421
+ "try_statement": """
422
+ (try_statement
423
+ body: (block) @try_body
424
+ (except_clause)* @except_clauses
425
+ (else_clause)? @else_clause
426
+ (finally_clause)? @finally_clause) @try_statement
427
+ """,
428
+ "except_clause": """
429
+ (except_clause
430
+ type: (_)? @exception_type
431
+ name: (identifier)? @exception_name
432
+ body: (block) @except_body) @except_clause
433
+ """,
434
+ "raise_statement": """
435
+ (raise_statement
436
+ (call
437
+ function: (identifier) @exception_name
438
+ arguments: (argument_list)? @exception_args)) @raise_statement
439
+ """,
440
+ "assert_statement": """
441
+ (assert_statement
442
+ (_) @assertion
443
+ (_)? @message) @assert_statement
444
+ """,
445
+ # --- Comprehensions ---
446
+ "list_comprehension": """
447
+ (list_comprehension
448
+ body: (_) @comprehension_body
449
+ (for_in_clause
450
+ left: (_) @comprehension_var
451
+ right: (_) @comprehension_iter)) @list_comprehension
452
+ """,
453
+ "dict_comprehension": """
454
+ (dictionary_comprehension
455
+ body: (pair
456
+ key: (_) @comprehension_key
457
+ value: (_) @comprehension_value)
458
+ (for_in_clause
459
+ left: (_) @comprehension_var
460
+ right: (_) @comprehension_iter)) @dict_comprehension
461
+ """,
462
+ "set_comprehension": """
463
+ (set_comprehension
464
+ body: (_) @comprehension_body
465
+ (for_in_clause
466
+ left: (_) @comprehension_var
467
+ right: (_) @comprehension_iter)) @set_comprehension
468
+ """,
469
+ "generator_expression": """
470
+ (generator_expression
471
+ body: (_) @generator_body
472
+ (for_in_clause
473
+ left: (_) @generator_var
474
+ right: (_) @generator_iter)) @generator_expression
475
+ """,
476
+ # --- Type Hints and Annotations ---
477
+ "type_hint": """
478
+ (typed_parameter
479
+ type: (_) @parameter_type) @typed_parameter
480
+ """,
481
+ "return_type": """
482
+ (function_definition
483
+ return_type: (_) @return_type) @function_with_return_type
484
+ """,
485
+ "variable_annotation": """
486
+ (assignment
487
+ type: (_) @variable_type) @annotated_assignment
488
+ """,
489
+ "type_alias": """
490
+ (type_alias_statement
491
+ name: (identifier) @alias_name
492
+ value: (_) @alias_type) @type_alias
493
+ """,
494
+ # --- Modern Python Features ---
495
+ "match_statement": """
496
+ (match_statement
497
+ subject: (_) @match_subject
498
+ body: (case_clause)+ @match_cases) @match_statement
499
+ """,
500
+ "case_clause": """
501
+ (case_clause
502
+ pattern: (_) @case_pattern
503
+ guard: (_)? @case_guard
504
+ consequence: (block) @case_body) @case_clause
505
+ """,
506
+ "walrus_operator": """
507
+ (named_expression
508
+ name: (identifier) @walrus_target
509
+ value: (_) @walrus_value) @walrus_operator
510
+ """,
511
+ "f_string": """
512
+ (formatted_string
513
+ (interpolation) @f_string_interpolation) @f_string
514
+ """,
515
+ "yield_expression": """
516
+ (yield
517
+ (_)? @yielded_value) @yield_expression
518
+ """,
519
+ "yield_from": """
520
+ (yield
521
+ "from" @yield_from_keyword
522
+ (_) @yielded_iterable) @yield_from_expression
523
+ """,
524
+ "await_expression": """
525
+ (await
526
+ (_) @awaited_expression) @await_expression
527
+ """,
528
+ # --- Comments and Docstrings ---
529
+ "comment": """
530
+ (comment) @comment
531
+ """,
532
+ "docstring": """
533
+ (expression_statement
534
+ (string) @docstring)
535
+ """,
536
+ "module_docstring": """
537
+ (module
538
+ (expression_statement
539
+ (string) @module_docstring))
540
+ """,
541
+ # --- Framework-specific Patterns ---
542
+ "django_model": """
543
+ (class_definition
544
+ name: (identifier) @model_name
545
+ superclasses: (argument_list
546
+ (identifier) @superclass
547
+ (#match? @superclass "Model|models.Model"))
548
+ body: (block) @model_body) @django_model
549
+ """,
550
+ "django_view": """
551
+ (class_definition
552
+ name: (identifier) @view_name
553
+ superclasses: (argument_list
554
+ (identifier) @superclass
555
+ (#match? @superclass "View|TemplateView|ListView|DetailView"))
556
+ body: (block) @view_body) @django_view
557
+ """,
558
+ "flask_route": """
559
+ (decorated_definition
560
+ (decorator
561
+ (call
562
+ function: (attribute
563
+ object: (identifier) @app_object
564
+ attribute: (identifier) @route_decorator
565
+ (#match? @route_decorator "route"))
566
+ arguments: (argument_list
567
+ (string) @route_path))) @flask_route_decorator
568
+ (function_definition
569
+ name: (identifier) @handler_name)) @flask_route
570
+ """,
571
+ "fastapi_endpoint": """
572
+ (decorated_definition
573
+ (decorator
574
+ (call
575
+ function: (attribute
576
+ object: (identifier) @app_object
577
+ attribute: (identifier) @http_method
578
+ (#match? @http_method "get|post|put|delete|patch"))
579
+ arguments: (argument_list
580
+ (string) @endpoint_path))) @fastapi_decorator
581
+ (function_definition
582
+ name: (identifier) @endpoint_name)) @fastapi_endpoint
583
+ """,
584
+ "dataclass": """
585
+ (decorated_definition
586
+ (decorator
587
+ (identifier) @decorator_name
588
+ (#match? @decorator_name "dataclass"))
589
+ (class_definition
590
+ name: (identifier) @dataclass_name)) @dataclass_definition
591
+ """,
592
+ # --- Name-only Extraction ---
593
+ "function_name": """
594
+ (function_definition
595
+ name: (identifier) @function_name)
596
+ """,
597
+ "class_name": """
598
+ (class_definition
599
+ name: (identifier) @class_name)
600
+ """,
601
+ "variable_name": """
602
+ (assignment
603
+ left: (identifier) @variable_name)
604
+ """,
605
+ # --- Advanced Patterns ---
606
+ "context_manager": """
607
+ (class_definition
608
+ body: (block
609
+ (function_definition
610
+ name: (identifier) @enter_method
611
+ (#match? @enter_method "__enter__"))
612
+ (function_definition
613
+ name: (identifier) @exit_method
614
+ (#match? @exit_method "__exit__")))) @context_manager_class
615
+ """,
616
+ "iterator": """
617
+ (class_definition
618
+ body: (block
619
+ (function_definition
620
+ name: (identifier) @iter_method
621
+ (#match? @iter_method "__iter__"))
622
+ (function_definition
623
+ name: (identifier) @next_method
624
+ (#match? @next_method "__next__")))) @iterator_class
625
+ """,
626
+ "metaclass": """
627
+ (class_definition
628
+ name: (identifier) @metaclass_name
629
+ superclasses: (argument_list
630
+ (identifier) @superclass
631
+ (#match? @superclass "type"))
632
+ body: (block) @metaclass_body) @metaclass_definition
633
+ """,
634
+ "abstract_method": """
635
+ (decorated_definition
636
+ (decorator
637
+ (identifier) @decorator_name
638
+ (#match? @decorator_name "abstractmethod"))
639
+ (function_definition
640
+ name: (identifier) @abstract_method_name)) @abstract_method
641
+ """,
642
+ }
643
+
644
+ # Query descriptions
645
+ PYTHON_QUERY_DESCRIPTIONS: dict[str, str] = {
646
+ "function": "Search Python function definitions",
647
+ "function_definition": "Search function definitions with details",
648
+ "async_function": "Search async function definitions",
649
+ "method": "Search method definitions within classes",
650
+ "lambda": "Search lambda expressions",
651
+ "class": "Search Python class definitions",
652
+ "class_definition": "Search class definitions with details",
653
+ "class_method": "Search class methods",
654
+ "constructor": "Search class constructors (__init__)",
655
+ "property": "Search property decorators",
656
+ "staticmethod": "Search static methods",
657
+ "classmethod": "Search class methods",
658
+ "variable": "Search variable assignments",
659
+ "assignment": "Search variable assignments",
660
+ "multiple_assignment": "Search multiple variable assignments",
661
+ "augmented_assignment": "Search augmented assignments (+=, -=, etc.)",
662
+ "global_statement": "Search global variable declarations",
663
+ "nonlocal_statement": "Search nonlocal variable declarations",
664
+ "import": "Search import statements",
665
+ "import_statement": "Search import statements with details",
666
+ "import_from": "Search from-import statements",
667
+ "import_from_list": "Search from-import with multiple names",
668
+ "aliased_import": "Search aliased imports (as keyword)",
669
+ "import_star": "Search star imports (from module import *)",
670
+ "decorator": "Search all decorators",
671
+ "decorator_simple": "Search simple decorators",
672
+ "decorator_call": "Search decorator calls with arguments",
673
+ "decorator_attribute": "Search attribute decorators",
674
+ "decorated_function": "Search decorated functions",
675
+ "decorated_class": "Search decorated classes",
676
+ "if_statement": "Search if statements",
677
+ "for_statement": "Search for loops",
678
+ "while_statement": "Search while loops",
679
+ "with_statement": "Search with statements (context managers)",
680
+ "async_with": "Search async with statements",
681
+ "async_for": "Search async for loops",
682
+ "try_statement": "Search try-except statements",
683
+ "except_clause": "Search except clauses",
684
+ "raise_statement": "Search raise statements",
685
+ "assert_statement": "Search assert statements",
686
+ "list_comprehension": "Search list comprehensions",
687
+ "dict_comprehension": "Search dictionary comprehensions",
688
+ "set_comprehension": "Search set comprehensions",
689
+ "generator_expression": "Search generator expressions",
690
+ "type_hint": "Search type hints on parameters",
691
+ "return_type": "Search function return type annotations",
692
+ "variable_annotation": "Search variable type annotations",
693
+ "type_alias": "Search type alias statements",
694
+ "match_statement": "Search match statements (Python 3.10+)",
695
+ "case_clause": "Search case clauses in match statements",
696
+ "walrus_operator": "Search walrus operator (:=)",
697
+ "f_string": "Search f-string literals",
698
+ "yield_expression": "Search yield expressions",
699
+ "yield_from": "Search yield from expressions",
700
+ "await_expression": "Search await expressions",
701
+ "comment": "Search all comments",
702
+ "docstring": "Search docstrings",
703
+ "module_docstring": "Search module-level docstrings",
704
+ "django_model": "Search Django model classes",
705
+ "django_view": "Search Django view classes",
706
+ "flask_route": "Search Flask route decorators",
707
+ "fastapi_endpoint": "Search FastAPI endpoint decorators",
708
+ "dataclass": "Search dataclass definitions",
709
+ "function_name": "Search function names only",
710
+ "class_name": "Search class names only",
711
+ "variable_name": "Search variable names only",
712
+ "context_manager": "Search context manager classes",
713
+ "iterator": "Search iterator classes",
714
+ "metaclass": "Search metaclass definitions",
715
+ "abstract_method": "Search abstract methods",
716
+ }
717
+
718
+ # Convert to ALL_QUERIES format for dynamic loader compatibility
719
+ ALL_QUERIES = {}
720
+ for query_name, query_string in PYTHON_QUERIES.items():
721
+ description = PYTHON_QUERY_DESCRIPTIONS.get(query_name, "No description")
722
+ ALL_QUERIES[query_name] = {"query": query_string, "description": description}
723
+
724
+ # Add legacy queries for backward compatibility
725
+ ALL_QUERIES["functions"] = {
726
+ "query": FUNCTIONS,
727
+ "description": "Search all function definitions (including async)",
728
+ }
729
+ ALL_QUERIES["classes"] = {"query": CLASSES, "description": "Search all class definitions"}
730
+ ALL_QUERIES["imports"] = {"query": IMPORTS, "description": "Search all import statements"}
731
+ ALL_QUERIES["variables"] = {"query": VARIABLES, "description": "Search all variable assignments"}
732
+ ALL_QUERIES["decorators"] = {"query": DECORATORS, "description": "Search all decorators"}
733
+ ALL_QUERIES["methods"] = {
734
+ "query": METHODS,
735
+ "description": "Search all method definitions within classes",
736
+ }
737
+ ALL_QUERIES["exceptions"] = {
738
+ "query": EXCEPTIONS,
739
+ "description": "Search exception handling and raise statements",
740
+ }
741
+ ALL_QUERIES["comprehensions"] = {
742
+ "query": COMPREHENSIONS,
743
+ "description": "Search list, dictionary, and set comprehensions",
744
+ }
745
+ ALL_QUERIES["comments"] = {"query": COMMENTS, "description": "Search comments and docstrings"}
746
+ ALL_QUERIES["type_hints"] = {
747
+ "query": TYPE_HINTS,
748
+ "description": "Search type hints and annotations",
749
+ }
750
+ ALL_QUERIES["async_patterns"] = {
751
+ "query": ASYNC_PATTERNS,
752
+ "description": "Search async/await patterns",
753
+ }
754
+ ALL_QUERIES["string_formatting"] = {
755
+ "query": STRING_FORMATTING,
756
+ "description": "Search f-strings and string formatting",
757
+ }
758
+ ALL_QUERIES["context_managers"] = {
759
+ "query": CONTEXT_MANAGERS,
760
+ "description": "Search context managers (with statements)",
761
+ }
762
+ ALL_QUERIES["lambdas"] = {"query": LAMBDAS, "description": "Search lambda expressions"}
763
+ ALL_QUERIES["modern_patterns"] = {
764
+ "query": MODERN_PATTERNS,
765
+ "description": "Search modern Python patterns (match/case, walrus operator)",
766
+ }
767
+
768
+ # Convenience aliases
769
+ ALL_QUERIES["function_names"] = {
770
+ "query": FUNCTIONS,
771
+ "description": "Function alias - search all function definitions",
772
+ }
773
+ ALL_QUERIES["class_names"] = {
774
+ "query": CLASSES,
775
+ "description": "Class alias - search all class definitions",
266
776
  }
777
+ ALL_QUERIES["all_declarations"] = {
778
+ "query": FUNCTIONS + "\n\n" + CLASSES + "\n\n" + VARIABLES,
779
+ "description": "Search all function, class, and variable declarations",
780
+ }
781
+
782
+
783
+ def get_python_query(name: str) -> str:
784
+ """
785
+ Get the specified Python query
786
+
787
+ Args:
788
+ name: Query name
789
+
790
+ Returns:
791
+ Query string
792
+
793
+ Raises:
794
+ ValueError: When query is not found
795
+ """
796
+ if name not in PYTHON_QUERIES:
797
+ available = list(PYTHON_QUERIES.keys())
798
+ raise ValueError(
799
+ f"Python query '{name}' does not exist. Available: {available}"
800
+ )
801
+
802
+ return PYTHON_QUERIES[name]
803
+
804
+
805
+ def get_python_query_description(name: str) -> str:
806
+ """
807
+ Get the description of the specified Python query
808
+
809
+ Args:
810
+ name: Query name
811
+
812
+ Returns:
813
+ Query description
814
+ """
815
+ return PYTHON_QUERY_DESCRIPTIONS.get(name, "No description")
267
816
 
268
817
 
269
818
  def get_query(name: str) -> str:
@@ -283,3 +832,13 @@ def get_all_queries() -> dict:
283
832
  def list_queries() -> list:
284
833
  """List all available query names."""
285
834
  return list(ALL_QUERIES.keys())
835
+
836
+
837
+ def get_available_python_queries() -> list[str]:
838
+ """
839
+ Get list of available Python queries
840
+
841
+ Returns:
842
+ List of query names
843
+ """
844
+ return list(PYTHON_QUERIES.keys())