Skip to content

[rejected AI] Path is generic on path_type - #3834

Closed
dhimasardinata wants to merge 1 commit into
pallets:mainfrom
dhimasardinata:fix-path-generic
Closed

dhimasardinata wants to merge 1 commit into
pallets:mainfrom
dhimasardinata:fix-path-generic

Conversation

@dhimasardinata

Copy link
Copy Markdown

Fixes #3822.

MRE from the issue now passes on mypy, pyright, and ty:

import pathlib
from typing_extensions import assert_type
import click

my_type = click.Path(file_okay=False, path_type=pathlib.Path)
path = click.prompt("Enter a name", type=my_type)
assert_type(path, pathlib.Path)

What changed (runtime unchanged, typing only):

  • Path is now ParamType[_PathValueT_co], Generic[_PathValueT_co] with a PEP 696 default (str | bytes | os.PathLike[str]), matching the existing ParamType second-param pattern for py3.10 compat.
  • __init__ overloads infer Path[T] from path_type: type[T]; bare Path() keeps the default union.
  • convert / coerce_path_result return the generic value type; self.type annotated as builtins.type[...] | None (avoids shadowing the type attribute).
  • Added tests/typing/typing_path.py assert_type coverage and CHANGES entry.

Verified:

  • mypy clean (29 files, strict)
  • pyright --ignoreexternal --verifytypes click 100% + 0 errors on new typing test and issue MRE
  • ruff check + ruff format --check clean
  • pytest tests/test_types.py 45 passed; manual runtime smoke (str/bytes/pathlib converts, Path[pathlib.Path] alias) unchanged.

Fixes #3822. Parameterize Path with its path_type value so convert,
coercion, and prompt() carry the narrowed return type. Runtime
unchanged.
@davidism

davidism commented Sep 3, 2026

Copy link
Copy Markdown
Member

@davidism davidism closed this Sep 3, 2026
@davidism davidism added the rejected AI Contribution rejected because of its untrustworthy AI origin label Sep 3, 2026
@davidism davidism changed the title Path is generic on path_type [rejected AI] Path is generic on path_type Sep 3, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

rejected AI Contribution rejected because of its untrustworthy AI origin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

click.Path should be generic on path_type

2 participants