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

HandleNotImplemented correctly inErrorDetail.__ne__#8538

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
tomchristie merged 1 commit intoencode:masterfromallanlewis:7433-handle-not-implemented-for-ErrorDetail-__ne__
Aug 1, 2022
Merged

HandleNotImplemented correctly inErrorDetail.__ne__#8538

tomchristie merged 1 commit intoencode:masterfromallanlewis:7433-handle-not-implemented-for-ErrorDetail-__ne__
Aug 1, 2022

Conversation

allanlewis
Copy link
Contributor

As per the sole commit:

PR#7531 resolved issue#7433 by updatingErrorDetails.__eq__ to correctly handle theNotImplemented case. However, Python 3.9 continues to issue the following warning:

DeprecationWarning: NotImplemented should not be used in a boolean context

This is because__ne__ still doesn't handle theNotImplemented case correctly. In order to avoid this warning, this commit makes the same change for__ne__ as previously made for__eq__.

refs#7433#7531

PR#7531 resolved issue#7433 by updating `ErrorDetails.__eq__` to correctlyhandle the `NotImplemented` case. However, Python 3.9 continues to issue thefollowing warning:    DeprecationWarning: NotImplemented should not be used in a boolean contextThis is because `__ne__` still doesn't handle the `NotImplemented` casecorrectly. In order to avoid this warning, this commit makes the same changefor `__ne__` as previously made for `__eq__`.
@tomchristie
Copy link
Member

Wait. Haven't we got both of these wrong? In what context isNotImplemented returned?
Surely it should beraised as an exception.

What code is returning it?

Copy link
Member

@tomchristietomchristie left a comment

Choose a reason for hiding this comment

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

Test - does this unapprove?

@allanlewis
Copy link
ContributorAuthor

Test - does this unapprove?

You need to "dismiss review" from the panel at the bottom.

Wait. Haven't we got both of these wrong? In what context is NotImplemented returned?
Surely it should be raised as an exception.

What code is returning it?

No, we've got this right, seethe docs:

NotImplemented
A special value which should be returned by the binary special methods (e.g.__eq__(),__lt__(),__add__(),__rsub__(), etc.) to indicate that the operation is not implemented with respect to the other type; may be returned by the in-place binary special methods (e.g.__imul__(),__iand__(), etc.) for the same purpose. It should not be evaluated in a boolean context.NotImplemented is the sole instance of thetypes.NotImplementedType type.
...
Changed in version 3.9: EvaluatingNotImplemented in a boolean context is deprecated. While it currently evaluates as true, it will emit aDeprecationWarning. It will raise aTypeError in a future version of Python.

@tomchristie
Copy link
Member

Gotcha, thanks.

@allanlewis
Copy link
ContributorAuthor

As I said in#7433 (comment) I'm happy to add a test for this case, given some guidance.

@tomchristie
Copy link
Member

Perhaps we're okay with it not having one.
PR#7531 didn't.
Consistency is a virtue, no?

@wieczorek1990
Copy link
Contributor

Please rename „r” to „result” or something else.

@tomchristietomchristie merged commit224168a intoencode:masterAug 1, 2022
@tomchristie
Copy link
Member

@wieczorek1990 The change here is consistent with the existing code above.

allanlewis reacted with rocket emoji

@allanlewis
Copy link
ContributorAuthor

Thanks,@tomchristie 🙏

tomchristie reacted with thumbs up emoji

@allanlewisallanlewis deleted the 7433-handle-not-implemented-for-ErrorDetail-__ne__ branchAugust 1, 2022 14:25
@wieczorek1990
Copy link
Contributor

I don’t think short names are good code.

@tomchristie
Copy link
Member

Generally agreed.
A pull request changing them forboth cases would be accepted.

@wieczorek1990
Copy link
Contributor

@tomchristie Here:#8585

sigvef pushed a commit to sigvef/django-rest-framework that referenced this pull requestDec 3, 2022
…encode#8538)PRencode#7531 resolved issueencode#7433 by updating `ErrorDetails.__eq__` to correctlyhandle the `NotImplemented` case. However, Python 3.9 continues to issue thefollowing warning:    DeprecationWarning: NotImplemented should not be used in a boolean contextThis is because `__ne__` still doesn't handle the `NotImplemented` casecorrectly. In order to avoid this warning, this commit makes the same changefor `__ne__` as previously made for `__eq__`.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tomchristietomchristietomchristie approved these changes

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

Successfully merging this pull request may close these issues.

3 participants
@allanlewis@tomchristie@wieczorek1990

[8]ページ先頭

©2009-2025 Movatter.jp