Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Remove redundant if check from argparser file.#8766

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
benjaminp merged 1 commit intopython:masterfromsp1rs:master
Jun 21, 2019
Merged
Changes fromall 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
6 changes: 2 additions & 4 deletionsLib/argparse.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1469,10 +1469,8 @@ def _get_optional_kwargs(self, *args, **kwargs):

# strings starting with two prefix characters are long options
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:
Copy link
Contributor

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.

Considerself.prefix_chars = {'-'}

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

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

if (option_string[0]inself.prefix_charsandlen(option_string)>1andoption_string[1]inself.prefix_chars):    ...

Copy link
ContributorAuthor

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 conditionoption_string[0] in self.prefix_chars.

Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
ContributorAuthor

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.     raiseelse:     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.

Copy link
ContributorAuthor

@sp1rssp1rsAug 17, 2018
edited
Loading

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 forelse. This looks cleaner. Please review.

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

# infer destination, '--foo-bar' -> 'foo_bar' and '-x' -> 'x'
dest = kwargs.pop('dest', None)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp