click icon indicating copy to clipboard operation
click copied to clipboard

[rejected AI] `click.Path.to_info_dict()` omits `executable` and `resolve_path` configurations

Open codeCraft-Ritik opened this issue 1 month ago • 1 comments

Outline

click.Path accepts executable: bool (added in Click 8.1) and resolve_path: bool. However, PathInfoDict and Path.to_info_dict() were never updated to include either attribute. When introspecting or serializing CLI metadata via param.type.to_info_dict() or Context.to_info_dict(), both executable and resolve_path are dropped from the dictionary.

Steps to Reproduce

import click

path_param = click.Path(executable=True, resolve_path=True)
info = path_param.to_info_dict()

print("Serialized dict:", info)
assert "executable" in info, "'executable' missing from to_info_dict()"
assert "resolve_path" in info, "'resolve_path' missing from to_info_dict()"

Traceback / Output

Serialized dict: {'exists': False, 'file_okay': True, 'dir_okay': True, 'writable': False, 'readable': True, 'allow_dash': False, 'param_type': 'Path', 'name': 'path'}
Traceback (most recent call last):
  File "test_info.py", line 7, in <module>
    assert "executable" in info, "'executable' missing from to_info_dict()"
AssertionError: 'executable' missing from to_info_dict()

Expected Behavior

The returned PathInfoDict must contain the executable and resolve_path fields:

{
    'param_type': 'Path',
    'name': 'path',
    'exists': False,
    'file_okay': True,
    'dir_okay': True,
    'writable': False,
    'readable': True,
    'allow_dash': False,
    'executable': True,
    'resolve_path': True,
}

Root Cause Analysis

In src/click/types.py:

  • PathInfoDict (lines 1050–1056) omits executable: bool and resolve_path: bool.
  • Path.to_info_dict() (lines 1136–1145) only unpacks exists, file_okay, dir_okay, writable, readable, and allow_dash.

Proposed Fix

--- a/src/click/types.py
+++ b/src/click/types.py
@@ -1054,6 +1054,8 @@ class PathInfoDict(ParamTypeInfoDict):
     writable: bool
     readable: bool
     allow_dash: bool
+    executable: bool
+    resolve_path: bool
 
 
 class Path(ParamType[_PathT_co, str | os.PathLike[str]], t.Generic[_PathT_co]):
@@ -1141,6 +1143,8 @@ class Path(ParamType[_PathT_co, str | os.PathLike[str]], t.Generic[_PathT_co]):
             "writable": self.writable,
             "readable": self.readable,
             "allow_dash": self.allow_dash,
+            "executable": self.executable,
+            "resolve_path": self.resolve_path,
             **super().to_info_dict(),
         }

Regression Test

def test_path_to_info_dict_preserves_executable_and_resolve_path():
    path_type = click.Path(executable=True, resolve_path=True)
    info = path_type.to_info_dict()
    assert info["executable"] is True
    assert info["resolve_path"] is True

Environment

  • Python version: 3.10 / 3.11 / 3.12 / 3.13 / 3.14
  • Click version: 8.1.0+ / 8.6.0a0 (main)

codeCraft-Ritik avatar Oct 23 '26 04:10 codeCraft-Ritik

https://palletsprojects.com/contributing/llm-ai

davidism avatar Oct 23 '26 04:10 davidism