diff options
author | Gregory P. Smith <greg@krypto.org> | 2016-08-07 16:06:27 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2016-08-07 16:06:27 (GMT) |
commit | d0d24fd1ae05a2aea84165cf0aae98f75a5203c8 (patch) | |
tree | 79cc2f86abbeb40149b52c3c2da4798387d57bb7 /Lib/unittest/mock.py | |
parent | 3cc38327b636e81b079edb0fd206ec678276e83f (diff) | |
parent | 9854789efec0c707fff871b32b2833f32b078fb3 (diff) | |
download | cpython-d0d24fd1ae05a2aea84165cf0aae98f75a5203c8.zip cpython-d0d24fd1ae05a2aea84165cf0aae98f75a5203c8.tar.gz cpython-d0d24fd1ae05a2aea84165cf0aae98f75a5203c8.tar.bz2 |
Issue #26750: unittest.mock.create_autospec() now works properly for
subclasses of property() and other data descriptors. Removes the never
publicly used, never documented unittest.mock.DescriptorTypes tuple.
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r-- | Lib/unittest/mock.py | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 4f91c44..ed915d2 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -60,14 +60,10 @@ def _is_exception(obj): ) -class _slotted(object): - __slots__ = ['a'] - - -DescriptorTypes = ( - type(_slotted.a), - property, -) +def _is_data_descriptor(obj): + # Data descriptors are Properties, slots, getsets and C data members. + return ((hasattr(obj, '__set__') or hasattr(obj, '__del__')) and + hasattr(obj, '__get__')) def _get_signature_object(func, as_instance, eat_self): @@ -2153,7 +2149,7 @@ def create_autospec(spec, spec_set=False, instance=False, _parent=None, _kwargs.update(kwargs) Klass = MagicMock - if type(spec) in DescriptorTypes: + if _is_data_descriptor(spec): # descriptors don't have a spec # because we don't know what type they return _kwargs = {} |