Skip to content

Change envvar type from list[str] to Sequence[str]#1610

Open
thakoreh wants to merge 4 commits intofastapi:masterfrom
thakoreh:fix-envvar-type-sequence
Open

Change envvar type from list[str] to Sequence[str]#1610
thakoreh wants to merge 4 commits intofastapi:masterfrom
thakoreh:fix-envvar-type-sequence

Conversation

@thakoreh
Copy link

Description

Fixes #283 - envvar type annotation should accept Sequence[str] instead of list[str]

Problem

The parameter type annotation used but Click accepts . This is overly restrictive and doesn't follow Python best practices for type hints.

From the issue:

Why List? Do we expect to mutate the data?
I'd expect immutable types allowed.
Maybe this should be generalized to an abstract interface such as Sequence or Iterable.

Solution

Changed to in all 4 occurrences in .

This allows users to pass any sequence type (tuple, list, etc.) for the parameter.

Changes

  • Added to imports from
  • Changed all 4 occurrences of to in envvar type annotations

The envvar parameter type annotation used list[str] but should accept
any sequence type (tuple, list, etc.). Changed to Sequence[str] which
is the abstract interface from collections.abc that Click also accepts.

Fixes: fastapi#283
The overload signatures use Sequence[str] but the implementation
annotations still used list[str], causing mypy overload checking errors.
Update models.py to use Sequence[str] for envvar parameter to match
the type annotations in params.py overloads.
@thakoreh
Copy link
Author

I noticed the mypy check is still failing. The issue is that while the PR updated OptionInfo and ArgumentInfo to use Sequence[str] for envvar, the TyperOption and TyperArgument classes in typer/core.py still use list[str].

You need to update the envvar parameter type in both classes in typer/core.py:

# In TyperArgument (around line 263)
envvar: str | Sequence[str] | None = None,

# In TyperOption (around line 410)
envvar: str | Sequence[str] | None = None,

The Sequence type is already imported at the top of the file.

I've created a branch with the fix at https://github.com/thakoreh/typer/tree/pr-1610 if you'd like to reference it.

Update core.py to use Sequence[str] for envvar to match params.py.
@svlandeg svlandeg added the feature New feature, enhancement or request label Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature, enhancement or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] envvar incorrect type: click accepts Sequence[str]

2 participants