GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Remove redundant if check from argparser file. by sp1rs · Pull Request #8766 · python/cpython

Conversation

@sp1rs

@sp1rs sp1rs commented Aug 14, 2018

Copy link
Copy Markdown
Contributor

Remove redundant if check from optional argument function in argparser.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sp1rs
Update argparse.py
43276dd
 Remove redundant if check from optional argument function in argparser.
@the-knights-who-say-ni

the-knights-who-say-ni commented Aug 14, 2018

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

When your account is ready, please add a comment in this pull request
and a Python core developer will remove the CLA not signed label
to make the bot check again.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@the-knights-who-say-ni the-knights-who-say-ni added the CLA not signed label Aug 14, 2018
@bedevere-bot bedevere-bot added the awaiting review label Aug 14, 2018
@sp1rs

sp1rs commented Aug 14, 2018

Copy link
Copy Markdown
Contributor Author

signed the CLA, Please remove the CLA not signed label.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andresdelfino andresdelfino mentioned this pull request Aug 14, 2018
Fix line breaks in NO_CLA_TEMPLATE python/the-knights-who-say-ni#161
Merged
asottile
asottile reviewed Aug 15, 2018
View reviewed changes
Comment thread Lib/argparse.py
option_strings.append(option_string)
if option_string[0] in self.prefix_chars:
if len(option_string) > 1:
if option_string[1] in self.prefix_chars:

@asottile asottile Aug 15, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these checks are redundant.

Consider self.prefix_chars = {'-'}

The left hand side requires '--foo' whereas your updated code incorrectly allows X-foo

I do think these conditions could be combined, perhaps something like:

if (
        option_string[0] in self.prefix_chars and
        len(option_string) > 1 and
        option_string[1] in self.prefix_chars
):
    ...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sp1rs sp1rs Aug 15, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the code from line no 1463. It checks for the condition option_string[0] in self.prefix_chars.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@asottile asottile Aug 15, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah indeed! Maybe use elif so that's more clear at a glance?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sp1rs sp1rs Aug 16, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do this.

if not option_string[0] in self.prefix_chars:
   # Some code. 
    raise
else:
     option_strings.append(option_string)
     if len(option_string) > 1 and option_string[1] in self.prefix_chars:
            long_option_strings.append(option_string)

Or the current code is also fine.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sp1rs sp1rs Aug 17, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asottile This change looks good. No need for else. This looks cleaner. Please review.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@miss-islington miss-islington removed the CLA not signed label Aug 16, 2018
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Aug 16, 2018
asottile
asottile approved these changes Aug 17, 2018
View reviewed changes

@asottile asottile left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah you;re right, seems fine -- didn't notice the statement in the middle so elif would be way more work than necessary.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting core review and removed awaiting review labels Aug 17, 2018
@sp1rs

sp1rs commented Aug 24, 2018

Copy link
Copy Markdown
Contributor Author

@asottile How and when will this Pull request be approved and merged to master?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@asottile

asottile commented Aug 24, 2018

Copy link
Copy Markdown
Contributor

No idea, I'm just a rando

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sp1rs

sp1rs commented Nov 29, 2018

Copy link
Copy Markdown
Contributor Author

@bedevere-bot Please someone review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@csabella
csabella requested review from benjaminp and merwok May 19, 2019 00:45
@sp1rs

sp1rs commented Jun 20, 2019

Copy link
Copy Markdown
Contributor Author

@benjaminp @merwok Please review the PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@merwok
merwok removed their request for review June 20, 2019 16:03
@benjaminp benjaminp added skip issue skip news labels Jun 21, 2019
@benjaminp
benjaminp merged commit b9600b0 into python:master Jun 21, 2019
@bedevere-bot bedevere-bot removed the awaiting core review label Jun 21, 2019
CuriousLearner added a commit to CuriousLearner/cpython that referenced this pull request Jun 21, 2019
@CuriousLearner
Merge branch 'master' into fix-issue24255
7bf6445
* master: (599 commits)
  Docs: Improved phrasing (pythonGH-14069)
  Remove redundant if check from optional argument function in argparse. (pythonGH-8766)
  bpo-37289: Add a test for if with ifexpr in the peephole optimiser to detect regressions (pythonGH-14127)
  Update What's New in Python 3.9 (pythonGH-14253)
  bpo-36511: Improve ARM32 buildbot scripts (pythonGH-14251)
  bpo-37151: remove _PyCFunction_FastCallDict (pythonGH-14269)
  Fix typo, 'widger' -> 'widget', in idlelib/tree.py (pythonGH-14263)
  Fix bpo number in News file. (pythonGH-14260)
  bpo-37342: Fix the incorrect nb_index's type in typeobj documentation (pythonGH-14241)
  Update What's New in Python 3.8 (pythonGH-14239)
  bpo-36710: Use tstate in pylifecycle.c (pythonGH-14249)
  Add missing single quote in io.TextIOWrapper.reconfigure documentation (pythonGH-14246)
  bpo-36511: Add buildbot scripts and fix tests for Windows ARM32 buildbot (pythonGH-13454)
  bpo-37333: Ensure IncludeTkinter has a value (pythonGH-14240)
  bpo-37331: Clarify format of socket handler messages in the documentation. (pythonGH-14234)
  bpo-37258: Not a bug, but added a unit test and updated documentation. (pythonGH-14229)
  bpo-36710: Remove PyImport_Cleanup() function (pythonGH-14221)
  Fix name of '\0'. (pythonGH-14222)
  bpo-36710: Add tstate parameter in import.c (pythonGH-14218)
  Document typing.ForwardRef (pythonGH-14216)
  ...
lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
@sp1rs @lisroach
Remove redundant if check from optional argument function in argparse. (
4b4b926
pythonGH-8766)
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
@sp1rs @DinoV
Remove redundant if check from optional argument function in argparse. (
5ee7076
pythonGH-8766)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@benjaminp benjaminp Awaiting requested review from benjaminp
1 more reviewer
@asottile asottile asottile approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip issue skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@sp1rs @the-knights-who-say-ni @asottile @benjaminp @bedevere-bot @miss-islington
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.