Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
35184edd
Commit
35184edd
authored
Nov 20, 2010
by
Michael Foord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 9732: __class__ no longer checked on objects by getattr_static
parent
e516265b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
Lib/inspect.py
Lib/inspect.py
+8
-1
Lib/test/test_inspect.py
Lib/test/test_inspect.py
+5
-1
No files found.
Lib/inspect.py
View file @
35184edd
...
...
@@ -1080,6 +1080,13 @@ def _check_class(klass, attr):
pass
return
_sentinel
def
_is_type
(
obj
):
try
:
_static_getmro
(
obj
)
except
TypeError
:
return
False
return
True
def
getattr_static
(
obj
,
attr
,
default
=
_sentinel
):
"""Retrieve attributes without triggering dynamic lookup via the
...
...
@@ -1093,7 +1100,7 @@ def getattr_static(obj, attr, default=_sentinel):
documentation for details.
"""
instance_result
=
_sentinel
if
not
isinstance
(
obj
,
type
):
if
not
_is_type
(
obj
):
instance_result
=
_check_instance
(
obj
,
attr
)
klass
=
type
(
obj
)
else
:
...
...
Lib/test/test_inspect.py
View file @
35184edd
...
...
@@ -860,11 +860,15 @@ class TestGetattrStatic(unittest.TestCase):
foo
=
3
class
Something
(
Base
):
executed
=
False
@
property
def
__class__
(
self
):
self
.
executed
=
True
return
object
self
.
assertEqual
(
inspect
.
getattr_static
(
Something
(),
'foo'
),
3
)
instance
=
Something
()
self
.
assertEqual
(
inspect
.
getattr_static
(
instance
,
'foo'
),
3
)
self
.
assertFalse
(
instance
.
executed
)
self
.
assertEqual
(
inspect
.
getattr_static
(
Something
,
'foo'
),
3
)
def
test_mro_as_property
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment