Skip to content

Commit ec3f4f5

Browse files
authored
undo some
1 parent 3ca04f4 commit ec3f4f5

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

Doc/library/inspect.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,8 +1614,8 @@ properties, will be invoked and :meth:`~object.__getattr__` and
16141614
may be called.
16151615

16161616
For cases where you want passive introspection, like documentation tools, this
1617-
can be inconvenient. :func:`getattr_static` has the same signature as :func:`getattr`
1618-
(modulo positional-only differences), but avoids executing code when it fetches attributes.
1617+
can be inconvenient. :func:`getattr_static` has a similar signature as :func:`getattr`
1618+
but avoids executing code when it fetches attributes.
16191619

16201620
.. function:: getattr_static(obj, attr)
16211621
getattr_static(obj, attr, default)
@@ -1645,15 +1645,18 @@ for arbitrary getset descriptors invoking these may trigger
16451645
code execution::
16461646

16471647
# example code for resolving the builtin descriptor types
1648-
slot_descriptor = type(slice.step)
1649-
getset_descriptor = type(property.__dict__['__name__'])
1648+
class _foo:
1649+
__slots__ = ['foo']
1650+
1651+
slot_descriptor = type(_foo.foo)
1652+
getset_descriptor = type(type(open(__file__)).name)
16501653
wrapper_descriptor = type(str.__dict__['__add__'])
16511654
descriptor_types = (slot_descriptor, getset_descriptor, wrapper_descriptor)
16521655

16531656
result = getattr_static(some_object, 'foo')
1654-
if isinstance(result, descriptor_types):
1657+
if type(result) in descriptor_types:
16551658
try:
1656-
result = result.__get__(some_object)
1659+
result = result.__get__()
16571660
except AttributeError:
16581661
# descriptors can raise AttributeError to
16591662
# indicate there is no underlying value

0 commit comments

Comments
 (0)