Skip to content

Tuple type options parses every character as an individual value #342

@midnight-repo

Description

@midnight-repo

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

import typer
from typing import Tuple
from pathlib import Path
app = typer.Typer()

@app.command()
def useless(): # at least two commands are needed for typer to run properly
    pass

@app.command()
def test(tupl: Tuple[Path] = typer.Option(None, '--tuple', '-t'), help='Tuple values'):

    for x in tupl:
        print(x)

app()

# RUN
# python3 app.py test -t AAA BBBBB

# PROBLEM
# should be interpreted as tuple("AAA", "BBBBB") but is interpreted as tuple("A", "A", "A")

# ERROR with :  python3 app.py test -t AAA BBBBB
# Error: Invalid value for '--tuple' / '-t': 1 values are required, but 3 were given.

# ERROR with : python3 app.py test -t A B
# Error: Got unexpected extra argument (B)

Description

I am trying to use a Tuple type option which is supposed to work as mentioned below :
python3 app.py --tuple value1 value2
This should be interpreted as tuple('value1', 'value2')
BUT
The app seems to interpret the tuple as being the individual characters of value1: tuple('v', 'a', 'l', 'u', 'e', ''1') and throws an error
Error: Invalid value for '--tuple' / '-t': 1 values are required, but 6 were given.

Operating System

Linux

Operating System Details

Ubuntu 20.04 LTS

Typer Version

0.4.0

Python Version

3.8.10

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion or problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions