mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-30533:Add function inspect.getmembers_static that does not call properties or dynamic properties. (#20911)
* Add function inspect.getmembers_static that does not call properties or dynamic properties. * update _getmembers args * Update Misc/NEWS.d/next/Library/2020-06-16-18-00-56.bpo-30533.StL57t.rst Co-authored-by: Itamar Ostricher <itamarost@gmail.com> * Update Lib/inspect.py Co-authored-by: Itamar Ostricher <itamarost@gmail.com> * Removes the copy pasted doc string Co-authored-by: Itamar Ostricher <itamarost@gmail.com> Co-authored-by: Dino Viehland <dinoviehland@gmail.com>
This commit is contained in:
parent
4b97d974ec
commit
af8c8caaf5
3 changed files with 40 additions and 4 deletions
|
@ -1215,6 +1215,23 @@ class TestClassesAndFunctions(unittest.TestCase):
|
|||
self.assertIn(('eggs', 'scrambled'), inspect.getmembers(A))
|
||||
self.assertIn(('eggs', 'spam'), inspect.getmembers(A()))
|
||||
|
||||
def test_getmembers_static(self):
|
||||
class A:
|
||||
@property
|
||||
def name(self):
|
||||
raise NotImplementedError
|
||||
@types.DynamicClassAttribute
|
||||
def eggs(self):
|
||||
raise NotImplementedError
|
||||
|
||||
a = A()
|
||||
instance_members = inspect.getmembers_static(a)
|
||||
class_members = inspect.getmembers_static(A)
|
||||
self.assertIn(('name', inspect.getattr_static(a, 'name')), instance_members)
|
||||
self.assertIn(('eggs', inspect.getattr_static(a, 'eggs')), instance_members)
|
||||
self.assertIn(('name', inspect.getattr_static(A, 'name')), class_members)
|
||||
self.assertIn(('eggs', inspect.getattr_static(A, 'eggs')), class_members)
|
||||
|
||||
def test_getmembers_with_buggy_dir(self):
|
||||
class M(type):
|
||||
def __dir__(cls):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue