Skip to content

gh-96548: argparse: Remove unused name variable when handling ArgumentTypeError#96549

Merged
JelleZijlstra merged 1 commit into
python:mainfrom
JonathonReinhart:argparse-unused-name
Sep 5, 2022
Merged

gh-96548: argparse: Remove unused name variable when handling ArgumentTypeError#96549
JelleZijlstra merged 1 commit into
python:mainfrom
JonathonReinhart:argparse-unused-name

Conversation

@JonathonReinhart

@JonathonReinhart JonathonReinhart commented Sep 4, 2022

Copy link
Copy Markdown
Contributor

This removes the unused name variable in the block where ArgumentTypeError is handled.

ArgumentTypeError errors are handled by showing just the string of the exception; unlike ValueError, the name (__name__) of the function is not included in the error message.

Fixes #96548

@bedevere-bot

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ghost

ghost commented Sep 4, 2022

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@JonathonReinhart

Copy link
Copy Markdown
Contributor Author

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

In my opinion, this fix is too trivial to warrant a NEWS entry. There is no user-visible change in behavior whatsoever.

@JelleZijlstra

Copy link
Copy Markdown
Member

Looks good, thanks. Going to change this in main only since it doesn't seem like it could cause a user-visible bug.

@JelleZijlstra JelleZijlstra merged commit 30878a7 into python:main Sep 5, 2022
@JonathonReinhart JonathonReinhart deleted the argparse-unused-name branch September 6, 2022 01:40
@JonathonReinhart

Copy link
Copy Markdown
Contributor Author

Looks good, thanks. Going to change this in main only since it doesn't seem like it could cause a user-visible bug.

Agreed, this is just a code cleanliness thing.

FWIW I discovered this while looking at the code to understand how exceptions from add_argument(type=) callbacks are handled. I noticed that when ValueError is raised, the __name__ of the function is used in the error message. And I was checking to see if the same applied to ArgumentTypeError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

argparse: 'name' variable unused when handling ArgumentTypeError

4 participants