-
-
Notifications
You must be signed in to change notification settings - Fork 104
Closed
Description
SystemExit
inherits from BaseException
and should be used very sparingly.
https://docs.python.org/3/library/exceptions.html#SystemExit
Currently, the docs and examples are using it in several places.
https://docs.pydantic.dev/latest/concepts/pydantic_settings/#subcommands-and-positional-arguments
I suspect the core issue is the leaking of an argparse implementation detail (which internally calls sys.exit
).
This is also perhaps the source of inconsistencies in exit codes when an error occurs. Sometimes it's 1 and sometimes it's 2.
Acceptance Criteria
- Remove usage of SystemExit in the docs
- CLI Examples should adhere to the standard style for Pydantic error catching (e.g.,
ValidationError
)
Possible Solutions
- In Python 3.9,
argparse
addedexit_on_error
flag to help solve this friction point withexit
being called. - Subclass
argparse.ArgumentParser
and override.exit()
orerror()
to raise the appropriate exception (fromstatus != 0
) instead of callingsys.exit
.
Metadata
Metadata
Assignees
Labels
No labels