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

bpo-5945: mapping.rst: PyMapping_Check(list) returns 1#144

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

Closed

Conversation

jbarlow83
Copy link

@jbarlow83jbarlow83 commentedFeb 17, 2017
edited by bedevere-bot
Loading

As discussed below, in Python 3, PyMapping_Check(list) returns 1. This behavior is justified by a developer as consistent with Python 3's internals. It is however surprising to C-API users (speaking from experience) and because it deviates from collections.abc.Mapping.

I think it is better to be vague than describe the implementation details.

https://mail.python.org/pipermail/python-dev/2009-May/089445.html

https://bugs.python.org/issue5945

@the-knights-who-say-ni

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 thePSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username onbugs.python.org (b.p.o) to verify you have signed the CLA. This is necessary for legal reasons before we can look at your contribution. Please follow these steps to help rectify the issue:

  1. If you don't have an account on b.p.o, pleasecreate one
  2. Make sure your GitHub username is listed in"Your Details" at b.p.o
  3. If you have not already done so, please sign thePSF contributor agreement
  4. If you just signed the CLA, pleasewait at least one US business day and then check "Your Details" onbugs.python.org to see if your account has been marked as having signed the CLA (the delay is due to a person having to manually check your signed CLA)
  5. Reply here saying you have completed the above steps

Thanks again to your contribution and we look forward to looking at it!

@jbarlow83jbarlow83 changed the titlemapping.rst: PyMapping_Check(list) returns 1bpo-5945: mapping.rst: PyMapping_Check(list) returns 1Feb 18, 2017
@@ -9,7 +9,8 @@ Mapping Protocol
.. c:function:: int PyMapping_Check(PyObject *o)

Return ``1`` if the object provides mapping protocol, and ``0`` otherwise. This
function always succeeds.
function always succeeds. This is not exactly equivalent to ``collections.abc.Mapping``.

Choose a reason for hiding this comment

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

Use double space after sentence-ending period. The line is too long, wrap it at column 79. Make collections.abc.Mapping a reference.

@serhiy-storchakaserhiy-storchaka added the docsDocumentation in the Doc dir labelFeb 18, 2017
@louisom
Copy link
Contributor

Should the commit rebase into one commit?

@jbarlow83
Copy link
Author

@grapherd The PR can be accepted as a squash merge in one click that will have the same effect as manually squashing it.

As discussed below, in Python 3, PyMapping_Check(list) returns 1. This behavior is justified by a developer as consistent with Python 3's internals. It is however surprising to C-API users (speaking from experience) and because it deviates from collections.abc.Mapping.https://mail.python.org/pipermail/python-dev/2009-May/089445.htmlSquashed a few revisions
@jbarlow83
Copy link
Author

jbarlow83 commentedFeb 27, 2017
edited
Loading

Rebased to HEAD and squashed

@Mariatta
Copy link
Member

I think this looks good now.@serhiy-storchaka would you like to take another look? I can do the backports.
Thanks :)

@rhettinger
Copy link
Contributor

No backports please.

@serhiy-storchaka
Copy link
Member

This is just the documentation fix. I think it should be backported.

But proposed wording doesn't LGTM. See my comment on the tracker.

@jbarlow83
Copy link
Author

Onbpo serhiy-storchaka wrote:

Proposed wording doesn't looks much informative to me. Maybe just say that PyMapping_Check() also returns 1 for sequences that support slicing? And recommendPyMapping_Check() && !PySequence_Check() for true mapping test?

There is no recommendation to usePyMapping_Check() && !PySequence_Check() in that thread. In fact developersrecommend against both PyMapping_Check and PySequence_Check as well:

(Author: Benjamin Peterson) Personally, I think PyMapping_Check and PySequence_Check should be deprecated and removed. Like their Python counterparts, operator.isMappingType() and operation.isSequenceType(), they are unreliable at best in the face of not LBYL and abcs

So I think it is appropriate to keep the proposed wording since it steers users to ABC checks and away from these APIs. If there is a change perhaps it should be explicitly "not recommended" in the documentation.

akruis pushed a commit to akruis/cpython that referenced this pull requestDec 20, 2017
…iew_newReplace copied code by a limited API function. This fixes the assertionerror caused by commit2eea952.
akruis pushed a commit to akruis/cpython that referenced this pull requestDec 20, 2017
Stackless contributes two tests to builtins: TaskletExit andTaskletExit.__init__. Therefore we have to adjust the limit.Add missing changelog entries (python#143,python#144).
@brettcannon
Copy link
Member

To try and help move older pull requests forward, we are going through and backfilling 'awaiting' labels on pull requests that are lacking the label. Based on the current reviews, the best we can tell in an automated fashion is that a core developer requested changes to be made to this pull request.

If/when the requested changes have been made, please leave a comment that says,I have made the requested changes; please review again. That will trigger a bot to flag this pull request as ready for a follow-up review.

@jbarlow83
Copy link
Author

jbarlow83 commentedFeb 23, 2018
edited
Loading

I have made the requested changes; please review again.

Given that several core developers suggested or concurred with deprecating this API (Benjamin Peterson, GvR, Raymond Hettinger) I marked it not recommended as an alternative to officially deprecating.

I think it is best to omit the suggestion to usePyMapping_Check() && !PySequence_Check(). It appears this test does not work in certain cases, becausePyMapping_Check is actually testing an CPython implementation detail. Instead I recommendedPyObject_IsInstance which steers the developer toward the modern ABC API.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@serhiy-storchaka: please review the changes made to this pull request.

akruis pushed a commit to akruis/cpython that referenced this pull requestMar 25, 2018
…iew_newReplace copied code by a limited API function. This fixes the assertionerror caused by commit2eea952.(cherry picked from commit096ad87)
akruis pushed a commit to akruis/cpython that referenced this pull requestMar 25, 2018
Stackless contributes two tests to builtins: TaskletExit andTaskletExit.__init__. Therefore we have to adjust the limit.Add missing changelog entries (python#143,python#144).(cherry picked from commit7327e4b)
Copy link
Contributor

@willingcwillingc left a comment

Choose a reason for hiding this comment

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

@jbarlow83 Thanks for the PR and the changes. To keep this PR from further languishing, I suppose it may be most efficient to update the wording to incorporate@serhiy-storchaka's suggestion.

Return ``1`` if the object provides mapping protocol, and ``0`` otherwise. This
function always succeeds.
**Not recommended.** Return ``1`` if the object provides the C-API mapping
protocol, and ``0`` otherwise. This function always succeeds. The C-API
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend using@serhiy-storchaka's suggested wording to move this PR forward.

The C-API mapping protocol is not equivalent to :class:collections.abc.Mapping, and also returns1 for sequences that support slicing. Use :c:func::PyObject_IsInstance instead.

PyMapping_Check() also returns 1 for sequences that support slicing.

@jbarlow83
Copy link
Author

@willingc Done

@willingc
Copy link
Contributor

Thanks@jbarlow83 for the quick response.

@serhiy-storchaka This looks good to me now. If you have no further changes, I recommend merging. Thanks.

@ilevkivskyi
Copy link
Member

Superseded by#7029

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

@serhiy-storchakaserhiy-storchakaserhiy-storchaka requested changes

@willingcwillingcwillingc approved these changes

Assignees
No one assigned
Labels
awaiting mergedocsDocumentation in the Doc dir
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

11 participants
@jbarlow83@the-knights-who-say-ni@louisom@Mariatta@rhettinger@serhiy-storchaka@brettcannon@bedevere-bot@willingc@ilevkivskyi@berkerpeksag

[8]ページ先頭

©2009-2025 Movatter.jp