X Tutup
The Wayback Machine - https://web.archive.org/web/20201101072401/https://github.com/python/cpython/pull/22906
Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a primer section for the descriptor howto guide #22906

Merged
merged 33 commits into from Oct 23, 2020

Conversation

@rhettinger
Copy link
Contributor

@rhettinger rhettinger commented Oct 23, 2020

Work in progress. A couple of sections remain.

Copy link

@dorox dorox left a comment

Is it possible to give more clarity on the attribute resolution method? The problem I had is that from this how-to it wasn't clear that assigning a descriptor as an attribute to a instance wouldn't make it's get and set methods resolved when that instance's attribute is called.

rhettinger added 2 commits Oct 23, 2020
rhettinger added 3 commits Oct 23, 2020
@rhettinger rhettinger changed the title [WIP] Create a primer section for the descriptor howto guide Create a primer section for the descriptor howto guide Oct 23, 2020
Copy link

@Edorka Edorka left a comment

A minor typo

Doc/howto/descriptor.rst Outdated Show resolved Hide resolved
rhettinger and others added 10 commits Oct 23, 2020
Co-authored-by: Eduardo Orive Vinuesa <edorka@gmail.com>
@rhettinger rhettinger merged commit 8d3d731 into python:master Oct 23, 2020
10 checks passed
10 checks passed
Docs
Details
Check for source changes
Details
Windows (x86)
Details
Windows (x64)
Details
macOS
Details
Ubuntu
Details
Azure Pipelines PR #20201023.77 succeeded
Details
Travis CI - Pull Request Build Passed
Details
bedevere/issue-number Issue report skipped
bedevere/news "skip news" label found
@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Oct 23, 2020

Thanks @rhettinger for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒🤖

miss-islington added a commit to miss-islington/cpython that referenced this pull request Oct 23, 2020
(cherry picked from commit 8d3d731)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
@bedevere-bot
Copy link

@bedevere-bot bedevere-bot commented Oct 23, 2020

GH-22918 is a backport of this pull request to the 3.9 branch.


Descriptors get invoked by the dot operator during attribute lookup. If a
descriptor is accessed indirectly with ``vars(some_class)[descriptor_name]``,
the descriptor instance is returned without invoking it.

This comment has been minimized.

@wimglenn

wimglenn Oct 23, 2020
Contributor

I wonder if it is worth mentioning here the more usual convention for returning the descriptor instance (checking if obj is None)? The indirection vars(vars(Person)['name']) is a little strange compared to vars(Person.name).

rhettinger pushed a commit that referenced this pull request Oct 23, 2020
…0-22918)
def newfunc(*args):
return self.f(klass, *args)
return self.f(cls, *args)
return newfunc
Comment on lines 875 to 877

This comment has been minimized.

@eriknw

eriknw Oct 23, 2020

Instead of using newfunc, wouldn't it be better to return types.MethodType(self.f, cls) similar to what is done in Function?

klass = type(obj)
def __get__(self, obj, cls=None):
if cls is None:
cls = type(obj)

This comment has been minimized.

@eriknw

eriknw Oct 23, 2020

The pure Python version doesn't capture the change #8405, which will call self.f.__get__(cls) if self.f has __get__. I think this behavior is surprising (and a little weird) and should be captured in this document, which doesn't shy away from nitty gritty details. I also happen to think this behavior of calling f.__get__ is incomplete and should instead call self.f.__get__(cls, cls).

lisroach added a commit to lisroach/cpython that referenced this pull request Oct 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants
You can’t perform that action at this time.
X Tutup