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-45356: fix incorrect access of class property in pydoc and inspect#29239

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

Open
akulakov wants to merge5 commits intopython:main
base:main
Choose a base branch
Loading
fromakulakov:45356-Fix-classproperty-pydoc-inspect
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletionsLib/inspect.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -486,6 +486,14 @@ def getmembers(object, predicate=None):

Attribute = namedtuple('Attribute', 'name kind defining_class object')

def _is_class_property(cls, name):
for base in cls.__mro__:
o = base.__dict__.get(name)
if isinstance(o, classmethod) and \
isinstance(o.__func__, property):
return True
return False

def classify_class_attrs(cls):
"""Return list of attribute-descriptor tuples.

Expand DownExpand Up@@ -546,6 +554,8 @@ def classify_class_attrs(cls):
try:
if name == '__dict__':
raise Exception("__dict__ is special, don't want the proxy")
if _is_class_property(cls, name):
raise Exception("class property")
get_obj = getattr(cls, name)
except Exception as exc:
pass
Expand Down
4 changes: 4 additions & 0 deletionsLib/pydoc.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -885,6 +885,8 @@ def spill(msg, attrs, predicate):
push(msg)
for name, kind, homecls, value in ok:
try:
if inspect._is_class_property(object, name):
raise Exception("class property")
value = getattr(object, name)
except Exception:
# Some descriptors may meet a failure in their __get__.
Expand DownExpand Up@@ -1368,6 +1370,8 @@ def spill(msg, attrs, predicate):
push(msg)
for name, kind, homecls, value in ok:
try:
if inspect._is_class_property(object, name):
raise Exception("class property")
value = getattr(object, name)
except Exception:
# Some descriptors may meet a failure in their __get__.
Expand Down
13 changes: 13 additions & 0 deletionsLib/test/test_pydoc.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -514,6 +514,19 @@ class object
" | ... and \\d+ other subclasses")
self.assertRegex(text, snip)

def test_classmethod_property(self):
# Issue 45356
class A:
@classmethod
@property
def a(self):
# BaseException because accessor of attributes in pydoc and in
# inspect catches Exception
raise BaseException
class B(A): pass
pydoc.render_doc(A)
pydoc.render_doc(B)

def test_builtin_with_child(self):
"""Tests help on builtin object which have only child classes.

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
:mod:`pydoc` ``help`` command, :meth:`~pydoc.HTMLDoc.docclass`,
:meth:`~pydoc.TextDoc.docclass`, and :func:`~inspect.classify_class_attrs`
will no longer execute the logic of a class property when examining a class
object that contains such property.

[8]ページ先頭

©2009-2025 Movatter.jp