🌐 AI搜索 & 代理 主页
Skip to content

Feat: Ignore arguments as examplef or dependency injection #704

@jochumdev

Description

@jochumdev

Hi!

Thanks for this great peace of software, I'm having a lot of fun with all the features cyclopts provides!

I'm using https://python-dependency-injector.ets-labs.org/wiring.html for a project, it uses an "@Inject" decorator to overwrite arg defaults.

Sadly cyclopts also wants to handle them which results in wired behavior.

This little patch allows me to ignore fields with an underscore prefix, I don't think this is backwards compatible that's why I didn't provide a PR.

diff --git a/cyclopts/argument/_collection.py b/cyclopts/argument/_collection.py
index 87abf08..00b5dfe 100644
--- a/cyclopts/argument/_collection.py
+++ b/cyclopts/argument/_collection.py
@@ -435,6 +435,9 @@ class ArgumentCollection(list[Argument]):
         docstring_lookup = extract_docstring_help(func) if parse_docstring else {}
         positional_index = 0
         for field_info in signature_parameters(func).values():
+            if not field_info.required and field_info.name[0] == "_":
+                continue
+
             if parse_docstring:
                 subkey_docstring_lookup = {
                     k[1:]: v for k, v in docstring_lookup.items() if k[0] == field_info.name and len(k) > 1

What do you think about this?

Kind regards,
René

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestimplementedthis feature has been implemented, but the issue **might** not be closed yet.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions