Skip to content

Path_fr does not use the default value during validation #237

@indigoviolet

Description

@indigoviolet

🐛 Bug report

If I specify a default value for a Path_fr parameter, the validation ignores it. This is pretty weird because clearly the value is present and used if I don't turn on this path_type validation.

To reproduce

from jsonargparse import CLI
from pathlib import Path

from jsonargparse.typing import Path_fr


def main(path: Path_fr = Path("test.py")):
    print(path)


if __name__ == "__main__":
    CLI(main, as_positional=False)
❯ python test.py --path test.py                               
test.py

❯ python test.py --help        
usage: test.py [-h] [--config CONFIG] [--print_config[=flags]] [--path PATH]

<function main at 0x7fc4001080d0>

optional arguments:
  -h, --help            Show this help message and exit.
  --config CONFIG       Path to a configuration file.
  --print_config[=flags]
                        Print the configuration after applying all other arguments and exit. The
                        optional flags customizes the output and are one or more keywords separated by
                        comma. The supported flags are: comments, skip_default, skip_null.
  --path PATH           (type: Path_fr, default: test.py)

❯ python test.py               
usage: test.py [-h] [--config CONFIG] [--print_config[=flags]] [--path PATH]
test.py: error: Configuration check failed :: Parser key "path":
  Not of type Path_fr: Expected path to be a string or a Path object.

Expected behavior

The validation should happen after applying the defaults.

Environment

  • jsonargparse version: 4.19.0
  • Python version (e.g., 3.9): 3.9.15
  • How jsonargparse was installed (e.g. pip install jsonargparse[all]): pip install jsonargparse
  • OS (e.g., Linux): Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions