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

gh-103492: Clarify SyntaxWarning with literal comparison#103493

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
hauntsaninja merged 10 commits intopython:mainfromhauntsaninja:gh-103492
Apr 24, 2023

Conversation

hauntsaninja
Copy link
Contributor

@hauntsaninjahauntsaninja commentedApr 13, 2023
edited by bedevere-bot
Loading

@hauntsaninjahauntsaninja marked this pull request as ready for reviewApril 13, 2023 00:59
Copy link
Member

@sobolevnsobolevn left a comment

Choose a reason for hiding this comment

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

Good idea, the code looks correct to me as well :)
Thank you!

@@ -277,7 +277,7 @@ def test_filename(self):
def test_warning(self):
# Test that the warning is only returned once.
with warnings_helper.check_warnings(
('"is" witha literal', SyntaxWarning),
('"is" withstr literal', SyntaxWarning),
Copy link
Member

Choose a reason for hiding this comment

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

would it be clearer to have"is" with literal of type 'str'?

Note that types are often in `:

>>> 1+'d'Traceback (most recent call last):  File "<stdin>", line 1, in <module>TypeError: unsupported operand type(s) for +: 'int' and 'str'

Copy link
Member

Choose a reason for hiding this comment

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

But consistently with only double quotes, or only single quotes?

Copy link
ContributorAuthor

@hauntsaninjahauntsaninjaApr 24, 2023
edited
Loading

Choose a reason for hiding this comment

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

Thanks, I've added quotes to the types. I kept the phrase'str' literal instead ofliteral of type 'str', since I found it a little easier to read and is similar to the way we just mention the types in the add example you give (instead of e.g. sayingvalue of type 'int' and value of type 'str')

I'm happy with whatever quote type, let me know!

: "\"is not\" with '%.200s' literal. Did you mean \"!=\"?";
expr_ty literal = !left ? e->v.Compare.left : right_expr;
return compiler_warn(
c, LOC(e), msg, Py_TYPE(literal->v.Constant.value)->tp_name
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
c,LOC(e),msg,Py_TYPE(literal->v.Constant.value)->tp_name
c,LOC(e),msg,infer_type(literal)->tp_name

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I had this originally, but it needed a forward reference / we know it's a Constant_kind so we could skip the switch :-)

I'll add it back!

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Addressed, let me know if I should move the function instead

return compiler_warn(c, LOC(e), msg);
? "\"is\" with '%.200s' literal. Did you mean \"==\"?"
: "\"is not\" with '%.200s' literal. Did you mean \"!=\"?";
expr_ty literal = !left ? e->v.Compare.left : right_expr;
Copy link
Member

Choose a reason for hiding this comment

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

left gets updated in each iteration, bute->v.Compare.left is always the same thing. Is this correct?

Should we just check the first item before the loop and then here just look atright_expr?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I might be missing something, butbool left = check_is_arg(e->v.Compare.left); happens once outside the loop and it's onlyright that is updated in each iteration.

Copy link
Member

Choose a reason for hiding this comment

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

line 2296?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Ah, of course! Thank you so much, this is buggy. I added the fix and a test case to catch the issue.

I think we can't do the first item check before the loop since all comparators may not beis, e.g.x == 3 is y, but let me know if I'm missing something!

@hauntsaninja
Copy link
ContributorAuthor

Thank you for the review!

@hauntsaninjahauntsaninja merged commitae25855 intopython:mainApr 24, 2023
carljm added a commit to carljm/cpython that referenced this pull requestApr 24, 2023
* main:pythongh-100227: Only Use deepfreeze for the Main Interpreter (pythongh-103794)pythongh-103492: Clarify SyntaxWarning with literal comparison (python#103493)pythongh-101100: Fix Sphinx warnings in `argparse` module (python#103289)
carljm added a commit to carljm/cpython that referenced this pull requestApr 24, 2023
* superopt:pythongh-100227: Only Use deepfreeze for the Main Interpreter (pythongh-103794)pythongh-103492: Clarify SyntaxWarning with literal comparison (python#103493)pythongh-101100: Fix Sphinx warnings in `argparse` module (python#103289)
@hauntsaninjahauntsaninja deleted the gh-103492 branchApril 29, 2023 07:53
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@hugovkhugovkhugovk left review comments

@iritkatrieliritkatrieliritkatriel approved these changes

@sobolevnsobolevnsobolevn approved these changes

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@hauntsaninja@iritkatriel@hugovk@sobolevn@bedevere-bot

[8]ページ先頭

©2009-2025 Movatter.jp