Skip to content

fix(cli): handle argparse different behavior after python 3.9 #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,13 @@ def main():
# This is for the command required constraint in 2.0
try:
args = parser.parse_args()
except TypeError:
raise NoCommandFoundError()
except (TypeError, SystemExit) as e:
# https://github.com/commitizen-tools/commitizen/issues/429
# argparse raises TypeError when non exist command is provided on Python < 3.9
# but raise SystemExit with exit code == 2 on Python 3.9
if isinstance(e, TypeError) or (isinstance(e, SystemExit) and e.code == 2):
raise NoCommandFoundError()
raise e

if args.name:
conf.update({"name": args.name})
Expand Down