Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 11, 2025

Scripts using cli.ExistingFile or other Predicate validators as type annotations crash with ValueError: 'FileArgument' is not in list since v1.10.

Root Cause

In _validate_args(), when processing type annotations from typing.get_type_hints(), the code assumes all annotation keys correspond to function parameters. In edge cases where get_type_hints() returns extra annotations (e.g., from class-level annotations), calling args_names.index(item) raises ValueError.

Changes

  • plumbum/cli/application.py: Add check to skip annotations not in parameter list

    # Before
    elif item != "return":
        positional[args_names.index(item)] = annotation
    
    # After  
    elif item != "return" and item in args_names:
        positional[args_names.index(item)] = annotation
  • tests/test_cli_annotations.py: Add test_extra_annotations_ignored() to validate fix with mocked get_type_hints() returning non-parameter annotations

Original prompt

This section details on the original issue you should resolve

<issue_title>cli.ExistingFile: Scripts crash after upgrade to 1.10</issue_title>
<issue_description>I use pb's cli.ExistingFile objects in my scripts to handle command line arguments of type "file".
This worked up to version 1.9 of pb.

With version 1.10, all my scripts now fail with error message 'FileArgument' is not in list.

The complete Traceback is

2025-11-09 11:04:58,418 - 💥️ - ERROR - extrahiere Barcodes aus PDF.py,569 - root.<module> - 'FileArgument' is not in list

Traceback (most recent call last):

  File "/Users/Guy/bin/extrahiere Barcodes aus PDF.py", line 565, in <module>

    ermittleDatenausBarcodesinPDF.run()

  File "/Users/Guy/Library/Python/3.12/lib/python/site-packages/plumbum/cli/application.py", line 608, in run

    ordered, tailargs = inst._validate_args(swfuncs, tailargs)

                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/Users/Guy/Library/Python/3.12/lib/python/site-packages/plumbum/cli/application.py", line 549, in _validate_args

    positional[args_names.index(item)] = annotation

               ^^^^^^^^^^^^^^^^^^^^^^

ValueError: 'FileArgument' is not in list

After reverting pbto 1.9, the error no longer occurs</issue_description>

<agent_instructions>This will need a test, currently FileArgument is not used in type annotations in existing tests. The OP might be doing something slightly unusual that used to work before, but I"m not sure what it is.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@henryiii This is probably from #621. How are you using it? Do you have an example of a failing script? I would have thought this would have been tested (tests/test_3_cli.py and tests/test_cli_annotations.py trigger this code path).

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix script crashes after upgrade to version 1.10 Fix ValueError when type annotations don't match function parameters Nov 11, 2025
Copilot AI requested a review from henryiii November 11, 2025 19:46
@henryiii
Copy link
Collaborator

I still want to see how this happens; the test case is manufacturing the situation but I'm not sure how it happens in normal code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cli.ExistingFile: Scripts crash after upgrade to 1.10

2 participants