wrapt 2.4.1__tar.gz → 2.4.2rc1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. {wrapt-2.4.1/src/wrapt.egg-info → wrapt-2.4.2rc1}/PKG-INFO +1 -1
  2. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/__init__.py +1 -1
  3. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/_wrappers.c +155 -37
  4. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/proxies.py +1 -1
  5. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/wrappers.py +18 -0
  6. {wrapt-2.4.1 → wrapt-2.4.2rc1/src/wrapt.egg-info}/PKG-INFO +1 -1
  7. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt.egg-info/SOURCES.txt +1 -0
  8. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_auto_object_proxy.py +38 -0
  9. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_lazy_object_proxy.py +39 -0
  10. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_type_module_attribute.py +137 -0
  11. wrapt-2.4.2rc1/tests/core/test_uninitialized_wrapper.py +272 -0
  12. {wrapt-2.4.1 → wrapt-2.4.2rc1}/LICENSE +0 -0
  13. {wrapt-2.4.1 → wrapt-2.4.2rc1}/MANIFEST.in +0 -0
  14. {wrapt-2.4.1 → wrapt-2.4.2rc1}/README.md +0 -0
  15. {wrapt-2.4.1 → wrapt-2.4.2rc1}/RELEASE.rst +0 -0
  16. {wrapt-2.4.1 → wrapt-2.4.2rc1}/pyproject.toml +0 -0
  17. {wrapt-2.4.1 → wrapt-2.4.2rc1}/setup.cfg +0 -0
  18. {wrapt-2.4.1 → wrapt-2.4.2rc1}/setup.py +0 -0
  19. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/__wrapt__.py +0 -0
  20. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/arguments.py +0 -0
  21. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/caching.py +0 -0
  22. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/decorators.py +0 -0
  23. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/exceptions.py +0 -0
  24. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/importer.py +0 -0
  25. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/patches.py +0 -0
  26. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/signature.py +0 -0
  27. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/synchronization.py +0 -0
  28. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt/weakrefs.py +0 -0
  29. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt-stubs/__init__.pyi +0 -0
  30. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt.egg-info/dependency_links.txt +0 -0
  31. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt.egg-info/not-zip-safe +0 -0
  32. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt.egg-info/requires.txt +0 -0
  33. {wrapt-2.4.1 → wrapt-2.4.2rc1}/src/wrapt.egg-info/top_level.txt +0 -0
  34. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/conftest.py +0 -0
  35. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/compat.py +0 -0
  36. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/module1.py +0 -0
  37. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/module2.py +0 -0
  38. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_adapter.py +0 -0
  39. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_adapter_annotations.py +0 -0
  40. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_adapter_kwonly.py +0 -0
  41. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_annotations.py +0 -0
  42. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_attribute_wrapper.py +0 -0
  43. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_callable_binding_no_args.py +0 -0
  44. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_callable_object_proxy.py +0 -0
  45. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_class.py +0 -0
  46. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_class_mro_entries.py +0 -0
  47. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_copy.py +0 -0
  48. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_decorator_state.py +0 -0
  49. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_decorators.py +0 -0
  50. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_deferred_patching.py +0 -0
  51. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_descriptor_get_class_access.py +0 -0
  52. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_descriptors.py +0 -0
  53. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_enabled_bool_error.py +0 -0
  54. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_entry_points.py +0 -0
  55. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_find_wrapper.py +0 -0
  56. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_formatargspec.py +0 -0
  57. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_function.py +0 -0
  58. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_function_wrapper.py +0 -0
  59. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_inheritance.py +0 -0
  60. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_inner_classmethod.py +0 -0
  61. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_inner_staticmethod.py +0 -0
  62. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_inplace_operators.py +0 -0
  63. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_instancemethod.py +0 -0
  64. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_lru_cache.py +0 -0
  65. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_memoize.py +0 -0
  66. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_missing_sentinel.py +0 -0
  67. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_monkey_patching.py +0 -0
  68. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_nested_function.py +0 -0
  69. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_object_proxy.py +0 -0
  70. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_object_proxy_hook.py +0 -0
  71. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_object_proxy_self_dict.py +0 -0
  72. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_object_proxy_type_checks.py +0 -0
  73. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_outer_classmethod.py +0 -0
  74. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_outer_staticmethod.py +0 -0
  75. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_pickle.py +0 -0
  76. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_post_import_hooks.py +0 -0
  77. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_pyerr_clear_propagation.py +0 -0
  78. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_resolve_path.py +0 -0
  79. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_runtime_type_hints.py +0 -0
  80. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_scoped_function_wrapper.py +0 -0
  81. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_synchronized_async.py +0 -0
  82. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_synchronized_lock.py +0 -0
  83. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_synchronized_markers.py +0 -0
  84. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_transient_function_wrapper.py +0 -0
  85. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_unwrap_object.py +0 -0
  86. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_update_attributes.py +0 -0
  87. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_weak_function_proxy.py +0 -0
  88. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_with_signature.py +0 -0
  89. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/core/test_wrapper_chain.py +0 -0
  90. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_auto_object_proxy_t1.out +0 -0
  91. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_auto_object_proxy_t1.py +0 -0
  92. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_decorator_t1.out +0 -0
  93. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_decorator_t1.py +0 -0
  94. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t1.out +0 -0
  95. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t1.py +0 -0
  96. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t2.out +0 -0
  97. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t2.py +0 -0
  98. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t3.out +0 -0
  99. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t3.py +0 -0
  100. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t4.out +0 -0
  101. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t4.py +0 -0
  102. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t5.out +0 -0
  103. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t5.py +0 -0
  104. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t6.out +0 -0
  105. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t6.py +0 -0
  106. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t7.out +0 -0
  107. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t7.py +0 -0
  108. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t8.out +0 -0
  109. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_cls_t8.py +0 -0
  110. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t1.out +0 -0
  111. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t1.py +0 -0
  112. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t2.out +0 -0
  113. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t2.py +0 -0
  114. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t3.out +0 -0
  115. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t3.py +0 -0
  116. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t4.out +0 -0
  117. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t4.py +0 -0
  118. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t5.out +0 -0
  119. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t5.py +0 -0
  120. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t6.out +0 -0
  121. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t6.py +0 -0
  122. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t7.out +0 -0
  123. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_function_wrapper_fn_t7.py +0 -0
  124. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_object_proxy_arithmetic_t1.out +0 -0
  125. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_object_proxy_arithmetic_t1.py +0 -0
  126. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_object_proxy_container_t1.out +0 -0
  127. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_object_proxy_container_t1.py +0 -0
  128. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_object_proxy_context_t1.out +0 -0
  129. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_object_proxy_context_t1.py +0 -0
  130. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_partial_callable_t1.out +0 -0
  131. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_partial_callable_t1.py +0 -0
  132. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_patch_function_wrapper_t1.out +0 -0
  133. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_patch_function_wrapper_t1.py +0 -0
  134. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_patching_primitives_t1.out +0 -0
  135. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_patching_primitives_t1.py +0 -0
  136. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_post_import_hooks_t1.out +0 -0
  137. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_post_import_hooks_t1.py +0 -0
  138. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_synchronized_lock_t1.out +0 -0
  139. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_synchronized_lock_t1.py +0 -0
  140. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_transient_function_wrapper_t1.out +0 -0
  141. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_transient_function_wrapper_t1.py +0 -0
  142. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_weak_function_proxy_t1.out +0 -0
  143. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_weak_function_proxy_t1.py +0 -0
  144. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t1.out +0 -0
  145. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t1.py +0 -0
  146. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t2.out +0 -0
  147. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t2.py +0 -0
  148. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t3.out +0 -0
  149. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t3.py +0 -0
  150. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t4.out +0 -0
  151. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t4.py +0 -0
  152. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t5.out +0 -0
  153. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t5.py +0 -0
  154. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t6.out +0 -0
  155. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t6.py +0 -0
  156. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t7.out +0 -0
  157. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t7.py +0 -0
  158. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t8.out +0 -0
  159. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/mypy/mypy_wrap_function_wrapper_t8.py +0 -0
  160. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/stress/runner.py +0 -0
  161. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/stress/stress_function_wrapper_call.py +0 -0
  162. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/stress/stress_init_reinit.py +0 -0
  163. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/stress/stress_inplace_ops.py +0 -0
  164. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/stress/stress_read_during_mutate.py +0 -0
  165. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tests/stress/stress_set_wrapped.py +0 -0
  166. {wrapt-2.4.1 → wrapt-2.4.2rc1}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wrapt
3
- Version: 2.4.1
3
+ Version: 2.4.2rc1
4
4
  Summary: Module for decorators, wrappers and monkey patching.
5
5
  Author-email: Graham Dumpleton <Graham.Dumpleton@gmail.com>
6
6
  License-Expression: BSD-2-Clause
@@ -13,7 +13,7 @@ def _format_version(parts):
13
13
  )
14
14
 
15
15
 
16
- __version_info__ = ("2", "4", "1")
16
+ __version_info__ = ("2", "4", "2", "rc1")
17
17
  __version__ = _format_version(__version_info__)
18
18
 
19
19
  from .__wrapt__ import (
@@ -446,6 +446,32 @@ static int raise_uninitialized_wrapper_error(WraptObjectProxyObject *object)
446
446
 
447
447
  /* ------------------------------------------------------------------------- */
448
448
 
449
+ /* Check that a wrapper specific field, as acquired by the caller, is not
450
+ * NULL, raising an error if it is. The additional fields of a partial or
451
+ * function wrapper are only ever set by __init__(), and together, so one
452
+ * being NULL means __init__() was never called, or did not complete. That
453
+ * is possible where a derived class overrides __init__() without calling
454
+ * that of the base class, or where an instance is created using __new__()
455
+ * alone, and __wrapped__ is then assigned directly such that the check for
456
+ * an uninitialized wrapper passes. An AttributeError naming the attribute
457
+ * by which the field is exposed is raised, that being what the pure Python
458
+ * implementation yields, since it holds the same state as instance
459
+ * attributes, which in this situation do not exist. */
460
+
461
+ static inline int wrapt_require_field(PyObject *object, PyObject *value,
462
+ const char *name)
463
+ {
464
+ if (value)
465
+ return 0;
466
+
467
+ PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%s'",
468
+ Py_TYPE(object)->tp_name, name);
469
+
470
+ return -1;
471
+ }
472
+
473
+ /* ------------------------------------------------------------------------- */
474
+
449
475
  /* Replace *op with a strong reference to the value to actually operate
450
476
  * on: the wrapped object if *op is a wrapt proxy, else *op itself. On
451
477
  * success the caller owns a reference to the replacement value and must
@@ -3033,9 +3059,54 @@ static PyObject *WraptObjectProxy_get_module(WraptObjectProxyObject *self)
3033
3059
 
3034
3060
  /* ------------------------------------------------------------------------- */
3035
3061
 
3062
+ /* Refresh the copy of __module__ or __doc__ held in the proxy's own dict
3063
+ * after the attribute has been deleted from the wrapped object. Deleting
3064
+ * __doc__ from a function, for example, leaves the attribute present with
3065
+ * a value of None, whereas on other objects it may be gone entirely. Record
3066
+ * what __init__ would have for a fresh proxy over the wrapped object in its
3067
+ * current state: the value if the attribute still exists, otherwise no
3068
+ * entry at all. */
3069
+
3070
+ static int WraptObjectProxy_refresh_cached_attr(WraptObjectProxyObject *self,
3071
+ PyObject *wrapped,
3072
+ PyObject *name)
3073
+ {
3074
+ PyObject *object = PyObject_GetAttr(wrapped, name);
3075
+
3076
+ if (object)
3077
+ {
3078
+ int result = PyDict_SetItem(self->dict, name, object);
3079
+ Py_DECREF(object);
3080
+ return result;
3081
+ }
3082
+
3083
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
3084
+ return -1;
3085
+
3086
+ PyErr_Clear();
3087
+
3088
+ if (PyDict_DelItem(self->dict, name) == -1)
3089
+ {
3090
+ if (!PyErr_ExceptionMatches(PyExc_KeyError))
3091
+ return -1;
3092
+ PyErr_Clear();
3093
+ }
3094
+
3095
+ return 0;
3096
+ }
3097
+
3098
+ /* ------------------------------------------------------------------------- */
3099
+
3100
+ /* The setters for __module__ and __doc__ are called with a NULL value when
3101
+ * the attribute is being deleted. PyObject_SetAttr() forwards a deletion to
3102
+ * the wrapped object, but the copy held in the proxy's own dict must then be
3103
+ * refreshed rather than stored, as the dict API rejects a NULL value. */
3104
+
3036
3105
  static int WraptObjectProxy_set_module(WraptObjectProxyObject *self,
3037
3106
  PyObject *value)
3038
3107
  {
3108
+ int result;
3109
+
3039
3110
  if (!self->wrapped)
3040
3111
  {
3041
3112
  if (raise_uninitialized_wrapper_error(self) == -1)
@@ -3049,14 +3120,16 @@ static int WraptObjectProxy_set_module(WraptObjectProxyObject *self,
3049
3120
  PyObject *wrapped = wrapt_acquire_wrapped(self);
3050
3121
 
3051
3122
  if (PyObject_SetAttr(wrapped, state->str_module, value) == -1)
3052
- {
3053
- Py_DECREF(wrapped);
3054
- return -1;
3055
- }
3123
+ result = -1;
3124
+ else if (value)
3125
+ result = PyDict_SetItem(self->dict, state->str_module, value);
3126
+ else
3127
+ result = WraptObjectProxy_refresh_cached_attr(self, wrapped,
3128
+ state->str_module);
3056
3129
 
3057
3130
  Py_DECREF(wrapped);
3058
3131
 
3059
- return PyDict_SetItemString(self->dict, "__module__", value);
3132
+ return result;
3060
3133
  }
3061
3134
 
3062
3135
  /* ------------------------------------------------------------------------- */
@@ -3087,6 +3160,8 @@ static PyObject *WraptObjectProxy_get_doc(WraptObjectProxyObject *self)
3087
3160
  static int WraptObjectProxy_set_doc(WraptObjectProxyObject *self,
3088
3161
  PyObject *value)
3089
3162
  {
3163
+ int result;
3164
+
3090
3165
  if (!self->wrapped)
3091
3166
  {
3092
3167
  if (raise_uninitialized_wrapper_error(self) == -1)
@@ -3100,14 +3175,16 @@ static int WraptObjectProxy_set_doc(WraptObjectProxyObject *self,
3100
3175
  PyObject *wrapped = wrapt_acquire_wrapped(self);
3101
3176
 
3102
3177
  if (PyObject_SetAttr(wrapped, state->str_doc, value) == -1)
3103
- {
3104
- Py_DECREF(wrapped);
3105
- return -1;
3106
- }
3178
+ result = -1;
3179
+ else if (value)
3180
+ result = PyDict_SetItem(self->dict, state->str_doc, value);
3181
+ else
3182
+ result = WraptObjectProxy_refresh_cached_attr(self, wrapped,
3183
+ state->str_doc);
3107
3184
 
3108
3185
  Py_DECREF(wrapped);
3109
3186
 
3110
- return PyDict_SetItemString(self->dict, "__doc__", value);
3187
+ return result;
3111
3188
  }
3112
3189
 
3113
3190
  /* ------------------------------------------------------------------------- */
@@ -3911,6 +3988,12 @@ static PyObject *WraptPartialCallableObjectProxy_call(
3911
3988
  PyObject *cargs = wrapt_acquire_field((PyObject *)self, &self->args);
3912
3989
  PyObject *ckwargs = wrapt_acquire_field((PyObject *)self, &self->kwargs);
3913
3990
 
3991
+ /* The captured keyword arguments are legitimately NULL when none were
3992
+ * supplied, so only the captured positional arguments are required. */
3993
+
3994
+ if (wrapt_require_field((PyObject *)self, cargs, "_self_args") == -1)
3995
+ goto finally;
3996
+
3914
3997
  fnargs = PyTuple_New(PyTuple_GET_SIZE(cargs) + PyTuple_GET_SIZE(args));
3915
3998
 
3916
3999
  if (!fnargs)
@@ -3952,7 +4035,7 @@ finally:
3952
4035
  Py_XDECREF(fnkwargs);
3953
4036
 
3954
4037
  Py_DECREF(wrapped);
3955
- Py_DECREF(cargs);
4038
+ Py_XDECREF(cargs);
3956
4039
  Py_XDECREF(ckwargs);
3957
4040
 
3958
4041
  return result;
@@ -3967,8 +4050,11 @@ static PyObject *WraptPartialCallableObjectProxy_get_self_args(
3967
4050
 
3968
4051
  value = wrapt_acquire_field((PyObject *)self, &self->args);
3969
4052
 
3970
- if (!value)
3971
- return PyTuple_New(0);
4053
+ /* See the comment for the equivalent getters of the function wrapper
4054
+ * as to why this fails rather than substituting an empty tuple. */
4055
+
4056
+ if (wrapt_require_field((PyObject *)self, value, "_self_args") == -1)
4057
+ return NULL;
3972
4058
 
3973
4059
  return value;
3974
4060
  }
@@ -3983,7 +4069,22 @@ static PyObject *WraptPartialCallableObjectProxy_get_self_kwargs(
3983
4069
  value = wrapt_acquire_field((PyObject *)self, &self->kwargs);
3984
4070
 
3985
4071
  if (!value)
4072
+ {
4073
+ /* The captured keyword arguments are legitimately NULL when none were
4074
+ * supplied, in which case an empty dictionary stands in for them. That
4075
+ * must be distinguished from __init__() never having been called, for
4076
+ * which the captured positional arguments, which are always set by
4077
+ * __init__(), will be NULL as well. */
4078
+
4079
+ PyObject *args = wrapt_acquire_field((PyObject *)self, &self->args);
4080
+
4081
+ if (wrapt_require_field((PyObject *)self, args, "_self_kwargs") == -1)
4082
+ return NULL;
4083
+
4084
+ Py_DECREF(args);
4085
+
3986
4086
  return PyDict_New();
4087
+ }
3987
4088
 
3988
4089
  return value;
3989
4090
  }
@@ -4329,6 +4430,12 @@ static PyObject *WraptFunctionWrapperBase_call(WraptFunctionWrapperObject *self,
4329
4430
  enabled = wrapt_acquire_field((PyObject *)self, &self->enabled);
4330
4431
  binding = wrapt_acquire_field((PyObject *)self, &self->binding);
4331
4432
 
4433
+ if (wrapt_require_field((PyObject *)self, instance, "_self_instance") == -1 ||
4434
+ wrapt_require_field((PyObject *)self, wrapper, "_self_wrapper") == -1 ||
4435
+ wrapt_require_field((PyObject *)self, enabled, "_self_enabled") == -1 ||
4436
+ wrapt_require_field((PyObject *)self, binding, "_self_binding") == -1)
4437
+ goto finally;
4438
+
4332
4439
  if (enabled != Py_None)
4333
4440
  {
4334
4441
  if (PyCallable_Check(enabled))
@@ -4465,6 +4572,13 @@ WraptFunctionWrapperBase_descr_get(WraptFunctionWrapperObject *self,
4465
4572
  binding = wrapt_acquire_field((PyObject *)self, &self->binding);
4466
4573
  parent = wrapt_acquire_field((PyObject *)self, &self->parent);
4467
4574
 
4575
+ if (wrapt_require_field((PyObject *)self, instance, "_self_instance") == -1 ||
4576
+ wrapt_require_field((PyObject *)self, wrapper, "_self_wrapper") == -1 ||
4577
+ wrapt_require_field((PyObject *)self, enabled, "_self_enabled") == -1 ||
4578
+ wrapt_require_field((PyObject *)self, binding, "_self_binding") == -1 ||
4579
+ wrapt_require_field((PyObject *)self, parent, "_self_parent") == -1)
4580
+ goto finally;
4581
+
4468
4582
  if (parent == Py_None)
4469
4583
  {
4470
4584
  if (PyUnicode_CompareWithASCIIString(binding, "builtin") == 0)
@@ -4647,6 +4761,15 @@ WraptFunctionWrapperBase_set_name(WraptFunctionWrapperObject *self,
4647
4761
 
4648
4762
  /* ------------------------------------------------------------------------- */
4649
4763
 
4764
+ /* The getters for the wrapper specific fields fail with AttributeError if
4765
+ * the field was never set, which means __init__() was not called. The
4766
+ * attribute lookup then falls through to __getattr__() and so on to the
4767
+ * wrapped object, which is the same outcome as for the pure Python
4768
+ * implementation, where these are instance attributes which in that case
4769
+ * do not exist. A value of None is not substituted, as that is a valid
4770
+ * value for most of these fields and so would be indistinguishable from
4771
+ * the state of a wrapper which had been initialized. */
4772
+
4650
4773
  static PyObject *
4651
4774
  WraptFunctionWrapperBase_get_self_instance(WraptFunctionWrapperObject *self,
4652
4775
  void *closure)
@@ -4655,10 +4778,8 @@ WraptFunctionWrapperBase_get_self_instance(WraptFunctionWrapperObject *self,
4655
4778
 
4656
4779
  value = wrapt_acquire_field((PyObject *)self, &self->instance);
4657
4780
 
4658
- if (!value)
4659
- {
4660
- Py_RETURN_NONE;
4661
- }
4781
+ if (wrapt_require_field((PyObject *)self, value, "_self_instance") == -1)
4782
+ return NULL;
4662
4783
 
4663
4784
  return value;
4664
4785
  }
@@ -4673,10 +4794,8 @@ WraptFunctionWrapperBase_get_self_wrapper(WraptFunctionWrapperObject *self,
4673
4794
 
4674
4795
  value = wrapt_acquire_field((PyObject *)self, &self->wrapper);
4675
4796
 
4676
- if (!value)
4677
- {
4678
- Py_RETURN_NONE;
4679
- }
4797
+ if (wrapt_require_field((PyObject *)self, value, "_self_wrapper") == -1)
4798
+ return NULL;
4680
4799
 
4681
4800
  return value;
4682
4801
  }
@@ -4691,10 +4810,8 @@ WraptFunctionWrapperBase_get_self_enabled(WraptFunctionWrapperObject *self,
4691
4810
 
4692
4811
  value = wrapt_acquire_field((PyObject *)self, &self->enabled);
4693
4812
 
4694
- if (!value)
4695
- {
4696
- Py_RETURN_NONE;
4697
- }
4813
+ if (wrapt_require_field((PyObject *)self, value, "_self_enabled") == -1)
4814
+ return NULL;
4698
4815
 
4699
4816
  return value;
4700
4817
  }
@@ -4709,10 +4826,8 @@ WraptFunctionWrapperBase_get_self_binding(WraptFunctionWrapperObject *self,
4709
4826
 
4710
4827
  value = wrapt_acquire_field((PyObject *)self, &self->binding);
4711
4828
 
4712
- if (!value)
4713
- {
4714
- Py_RETURN_NONE;
4715
- }
4829
+ if (wrapt_require_field((PyObject *)self, value, "_self_binding") == -1)
4830
+ return NULL;
4716
4831
 
4717
4832
  return value;
4718
4833
  }
@@ -4727,10 +4842,8 @@ WraptFunctionWrapperBase_get_self_parent(WraptFunctionWrapperObject *self,
4727
4842
 
4728
4843
  value = wrapt_acquire_field((PyObject *)self, &self->parent);
4729
4844
 
4730
- if (!value)
4731
- {
4732
- Py_RETURN_NONE;
4733
- }
4845
+ if (wrapt_require_field((PyObject *)self, value, "_self_parent") == -1)
4846
+ return NULL;
4734
4847
 
4735
4848
  return value;
4736
4849
  }
@@ -4745,10 +4858,8 @@ WraptFunctionWrapperBase_get_self_owner(WraptFunctionWrapperObject *self,
4745
4858
 
4746
4859
  value = wrapt_acquire_field((PyObject *)self, &self->owner);
4747
4860
 
4748
- if (!value)
4749
- {
4750
- Py_RETURN_NONE;
4751
- }
4861
+ if (wrapt_require_field((PyObject *)self, value, "_self_owner") == -1)
4862
+ return NULL;
4752
4863
 
4753
4864
  return value;
4754
4865
  }
@@ -4843,6 +4954,13 @@ WraptBoundFunctionWrapper_call(WraptFunctionWrapperObject *self, PyObject *args,
4843
4954
  binding = wrapt_acquire_field((PyObject *)self, &self->binding);
4844
4955
  owner = wrapt_acquire_field((PyObject *)self, &self->owner);
4845
4956
 
4957
+ if (wrapt_require_field((PyObject *)self, instance, "_self_instance") == -1 ||
4958
+ wrapt_require_field((PyObject *)self, wrapper, "_self_wrapper") == -1 ||
4959
+ wrapt_require_field((PyObject *)self, enabled, "_self_enabled") == -1 ||
4960
+ wrapt_require_field((PyObject *)self, binding, "_self_binding") == -1 ||
4961
+ wrapt_require_field((PyObject *)self, owner, "_self_owner") == -1)
4962
+ goto finally;
4963
+
4846
4964
  if (enabled != Py_None)
4847
4965
  {
4848
4966
  if (PyCallable_Check(enabled))
@@ -70,7 +70,7 @@ def __wrapper_await__(self):
70
70
  return (yield from self.__wrapped__.__await__())
71
71
 
72
72
 
73
- def __wrapper_get__(self, instance, owner):
73
+ def __wrapper_get__(self, instance, owner=None):
74
74
  return self.__wrapped__.__get__(instance, owner)
75
75
 
76
76
 
@@ -36,6 +36,10 @@ class _ObjectProxyMethods:
36
36
  def __module__(self, value):
37
37
  self.__wrapped__.__module__ = value
38
38
 
39
+ @__module__.deleter
40
+ def __module__(self):
41
+ del self.__wrapped__.__module__
42
+
39
43
  @property
40
44
  def __doc__(self):
41
45
  return self.__wrapped__.__doc__
@@ -44,6 +48,10 @@ class _ObjectProxyMethods:
44
48
  def __doc__(self, value):
45
49
  self.__wrapped__.__doc__ = value
46
50
 
51
+ @__doc__.deleter
52
+ def __doc__(self):
53
+ del self.__wrapped__.__doc__
54
+
47
55
  # We similar use a property for __dict__. We need __dict__ to be
48
56
  # explicit to ensure that vars() works as expected.
49
57
 
@@ -937,6 +945,16 @@ class BoundFunctionWrapper(_FunctionWrapperBase):
937
945
  super().__setattr__(name, value)
938
946
 
939
947
  def __getattr__(self, name):
948
+ # This is only reached for _self_parent when that attribute was
949
+ # never set, which means __init__() was not called. It has to fail
950
+ # here, as the lookup of it below would otherwise come straight
951
+ # back in and recurse without end.
952
+
953
+ if name == "_self_parent":
954
+ raise AttributeError(
955
+ f"'{type(self).__name__}' object has no attribute '{name}'"
956
+ )
957
+
940
958
  if self._self_parent is not None:
941
959
  try:
942
960
  return getattr(self._self_parent, name)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wrapt
3
- Version: 2.4.1
3
+ Version: 2.4.2rc1
4
4
  Summary: Module for decorators, wrappers and monkey patching.
5
5
  Author-email: Graham Dumpleton <Graham.Dumpleton@gmail.com>
6
6
  License-Expression: BSD-2-Clause
@@ -80,6 +80,7 @@ tests/core/test_synchronized_lock.py
80
80
  tests/core/test_synchronized_markers.py
81
81
  tests/core/test_transient_function_wrapper.py
82
82
  tests/core/test_type_module_attribute.py
83
+ tests/core/test_uninitialized_wrapper.py
83
84
  tests/core/test_unwrap_object.py
84
85
  tests/core/test_update_attributes.py
85
86
  tests/core/test_weak_function_proxy.py
@@ -169,6 +169,43 @@ class TestAutoObjectProxy(unittest.TestCase):
169
169
  self.assertRaises(TypeError, os.fspath, proxy)
170
170
  self.assertFalse(isinstance(proxy, os.PathLike))
171
171
 
172
+ def test_descriptor_optional_owner(self):
173
+ def method(instance):
174
+ return instance
175
+
176
+ instance = object()
177
+
178
+ for descriptor in (method, property(method)):
179
+ with self.subTest(descriptor=descriptor):
180
+ proxy = wrapt.AutoObjectProxy(descriptor)
181
+
182
+ self.assertEqual(proxy.__get__(instance), descriptor.__get__(instance))
183
+ self.assertEqual(
184
+ proxy.__get__(instance, None), descriptor.__get__(instance, None)
185
+ )
186
+ self.assertEqual(
187
+ proxy.__get__(None, object), descriptor.__get__(None, object)
188
+ )
189
+
190
+ def test_descriptor_optional_owner_required_by_wrapped(self):
191
+ # A descriptor implemented in Python can require the owner argument,
192
+ # as Python always supplies it on attribute lookup. When the owner
193
+ # is omitted in a manual call through the proxy, it is None which
194
+ # must be passed to the wrapped descriptor.
195
+
196
+ class Descriptor:
197
+ def __get__(self, instance, owner):
198
+ return (instance, owner)
199
+
200
+ instance = object()
201
+
202
+ proxy = wrapt.AutoObjectProxy(Descriptor())
203
+
204
+ self.assertEqual(proxy.__get__(instance), (instance, None))
205
+ self.assertEqual(proxy.__get__(instance, None), (instance, None))
206
+ self.assertEqual(proxy.__get__(instance, object), (instance, object))
207
+ self.assertEqual(proxy.__get__(None, object), (None, object))
208
+
172
209
  def test_descriptor(self):
173
210
  class Descriptor:
174
211
  def __init__(self, value):
@@ -391,6 +428,7 @@ class TestAutoObjectProxyReassignment(unittest.TestCase):
391
428
  self.assertFalse(hasattr(proxy, "__get__"))
392
429
  proxy.__wrapped__ = Descriptor()
393
430
  self.assertTrue(hasattr(proxy, "__get__"))
431
+ self.assertEqual(proxy.__get__(object()), 42)
394
432
 
395
433
  def test_get_removed_on_reassignment(self):
396
434
  class Descriptor:
@@ -22,6 +22,45 @@ class TestLazyObjectProxy(unittest.TestCase):
22
22
  self.assertEqual(int(proxy), 42)
23
23
  self.assertEqual(status["created"], 1)
24
24
 
25
+ def test_descriptor_optional_owner(self):
26
+ def method(instance):
27
+ return instance
28
+
29
+ instance = object()
30
+
31
+ for descriptor in (method, property(method)):
32
+ with self.subTest(descriptor=descriptor):
33
+ proxy = wrapt.LazyObjectProxy(
34
+ lambda: descriptor, interface=type(descriptor)
35
+ )
36
+
37
+ self.assertEqual(proxy.__get__(instance), descriptor.__get__(instance))
38
+ self.assertEqual(
39
+ proxy.__get__(instance, None), descriptor.__get__(instance, None)
40
+ )
41
+ self.assertEqual(
42
+ proxy.__get__(None, object), descriptor.__get__(None, object)
43
+ )
44
+
45
+ def test_descriptor_optional_owner_required_by_wrapped(self):
46
+ # A descriptor implemented in Python can require the owner argument,
47
+ # as Python always supplies it on attribute lookup. When the owner
48
+ # is omitted in a manual call through the proxy, it is None which
49
+ # must be passed to the wrapped descriptor.
50
+
51
+ class Descriptor:
52
+ def __get__(self, instance, owner):
53
+ return (instance, owner)
54
+
55
+ instance = object()
56
+
57
+ proxy = wrapt.LazyObjectProxy(Descriptor, interface=Descriptor)
58
+
59
+ self.assertEqual(proxy.__get__(instance), (instance, None))
60
+ self.assertEqual(proxy.__get__(instance, None), (instance, None))
61
+ self.assertEqual(proxy.__get__(instance, object), (instance, object))
62
+ self.assertEqual(proxy.__get__(None, object), (None, object))
63
+
25
64
  def test_lazy_import(self):
26
65
  if "sched" in sys.modules:
27
66
  del sys.modules["sched"]
@@ -272,6 +272,129 @@ class TestSetModuleAndDoc(unittest.TestCase):
272
272
  self.assertEqual(target.__module__, "override_module")
273
273
 
274
274
 
275
+ # -- Deleting __module__ and __doc__ tests --
276
+
277
+
278
+ class TestDeleteModuleAndDoc(unittest.TestCase):
279
+ """Verify deleting __module__ and __doc__ on instances is forwarded to
280
+ the wrapped object, in the same way as setting them. Targets are
281
+ created per test rather than shared, as deletion changes them."""
282
+
283
+ @staticmethod
284
+ def make_function():
285
+ def target():
286
+ "target documentation"
287
+ pass
288
+ return target
289
+
290
+ @staticmethod
291
+ def make_class():
292
+ class Target:
293
+ "target documentation"
294
+ return Target
295
+
296
+ @staticmethod
297
+ def delete_outcome(obj, name):
298
+ # Return None if deletion succeeds, else the exception type and
299
+ # message, so the outcome via a proxy can be compared with the
300
+ # outcome of the same deletion made directly on the target.
301
+ try:
302
+ delattr(obj, name)
303
+ except Exception as e:
304
+ return (type(e), str(e))
305
+ return None
306
+
307
+ def test_delete_module_on_object_proxy(self):
308
+ target = self.make_function()
309
+ wrapper = wrapt.ObjectProxy(target)
310
+ del wrapper.__module__
311
+ self.assertIsNone(target.__module__)
312
+ self.assertIsNone(wrapper.__module__)
313
+
314
+ def test_delete_doc_on_object_proxy(self):
315
+ target = self.make_function()
316
+ wrapper = wrapt.ObjectProxy(target)
317
+ del wrapper.__doc__
318
+ self.assertIsNone(target.__doc__)
319
+ self.assertIsNone(wrapper.__doc__)
320
+
321
+ def test_delete_module_after_set(self):
322
+ target = self.make_function()
323
+ wrapper = wrapt.ObjectProxy(target)
324
+ wrapper.__module__ = "override_module"
325
+ del wrapper.__module__
326
+ self.assertIsNone(target.__module__)
327
+ self.assertIsNone(wrapper.__module__)
328
+
329
+ def test_delete_doc_after_set(self):
330
+ target = self.make_function()
331
+ wrapper = wrapt.ObjectProxy(target)
332
+ wrapper.__doc__ = "override doc"
333
+ del wrapper.__doc__
334
+ self.assertIsNone(target.__doc__)
335
+ self.assertIsNone(wrapper.__doc__)
336
+
337
+ def test_delete_module_on_function_wrapper(self):
338
+ def my_wrapper(wrapped, instance, args, kwargs):
339
+ return wrapped(*args, **kwargs)
340
+ target = self.make_function()
341
+ wrapper = wrapt.FunctionWrapper(target, my_wrapper)
342
+ del wrapper.__module__
343
+ self.assertIsNone(target.__module__)
344
+ self.assertIsNone(wrapper.__module__)
345
+
346
+ def test_delete_doc_on_function_wrapper(self):
347
+ def my_wrapper(wrapped, instance, args, kwargs):
348
+ return wrapped(*args, **kwargs)
349
+ target = self.make_function()
350
+ wrapper = wrapt.FunctionWrapper(target, my_wrapper)
351
+ del wrapper.__doc__
352
+ self.assertIsNone(target.__doc__)
353
+ self.assertIsNone(wrapper.__doc__)
354
+
355
+ def test_delete_module_on_user_subclass(self):
356
+ class MyProxy(wrapt.ObjectProxy):
357
+ pass
358
+ target = self.make_function()
359
+ wrapper = MyProxy(target)
360
+ del wrapper.__module__
361
+ self.assertIsNone(target.__module__)
362
+ self.assertIsNone(wrapper.__module__)
363
+
364
+ def test_delete_doc_on_user_subclass(self):
365
+ class MyProxy(wrapt.ObjectProxy):
366
+ pass
367
+ target = self.make_function()
368
+ wrapper = MyProxy(target)
369
+ del wrapper.__doc__
370
+ self.assertIsNone(target.__doc__)
371
+ self.assertIsNone(wrapper.__doc__)
372
+
373
+ def test_delete_module_on_class_target(self):
374
+ # A class does not permit deletion of __module__. The outcome via
375
+ # the proxy must match a direct deletion on an equivalent class.
376
+ expected = self.delete_outcome(self.make_class(), "__module__")
377
+ wrapper = wrapt.ObjectProxy(self.make_class())
378
+ self.assertEqual(self.delete_outcome(wrapper, "__module__"), expected)
379
+
380
+ def test_delete_doc_on_class_target(self):
381
+ expected = self.delete_outcome(self.make_class(), "__doc__")
382
+ wrapper = wrapt.ObjectProxy(self.make_class())
383
+ self.assertEqual(self.delete_outcome(wrapper, "__doc__"), expected)
384
+
385
+ def test_proxy_state_matches_fresh_proxy_after_delete(self):
386
+ # After deletion the proxy's own instance dictionary must be the
387
+ # same as for a proxy newly created over the wrapped object in
388
+ # its current state, so the C extension's cached copies of the
389
+ # attributes do not go stale or linger.
390
+ target = self.make_function()
391
+ wrapper = wrapt.ObjectProxy(target)
392
+ del wrapper.__module__
393
+ del wrapper.__doc__
394
+ fresh = wrapt.ObjectProxy(target)
395
+ self.assertEqual(dict(wrapper.__self_dict__), dict(fresh.__self_dict__))
396
+
397
+
275
398
  # -- Wrapped replacement tests --
276
399
 
277
400
 
@@ -365,6 +488,20 @@ class TestNonInternedAttributeNames(unittest.TestCase):
365
488
  self.assertEqual(proxy.__module__, "set.module")
366
489
  self.assertEqual(proxy.__doc__, "set doc")
367
490
 
491
+ def test_delete_module_and_doc_via_non_interned_name(self):
492
+ def function():
493
+ """original doc"""
494
+
495
+ proxy = BaseObjectProxy(function)
496
+
497
+ delattr(proxy, self.dynamic("__module__"))
498
+ delattr(proxy, self.dynamic("__doc__"))
499
+
500
+ self.assertIsNone(function.__module__)
501
+ self.assertIsNone(function.__doc__)
502
+ self.assertIsNone(proxy.__module__)
503
+ self.assertIsNone(proxy.__doc__)
504
+
368
505
 
369
506
  if __name__ == "__main__":
370
507
  unittest.main()