wrapt 2.2.2rc3__tar.gz → 2.3.0.dev1__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.
- {wrapt-2.2.2rc3/src/wrapt.egg-info → wrapt-2.3.0.dev1}/PKG-INFO +1 -1
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt/__init__.py +1 -1
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt/_wrappers.c +64 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt/proxies.py +13 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt/wrappers.py +14 -2
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt-stubs/__init__.pyi +17 -5
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1/src/wrapt.egg-info}/PKG-INFO +1 -1
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt.egg-info/SOURCES.txt +6 -7
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/conftest.py +1 -7
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_auto_object_proxy.py +53 -0
- wrapt-2.2.2rc3/tests/core/test_formatargspec_py38.py → wrapt-2.3.0.dev1/tests/core/test_formatargspec.py +41 -2
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_object_proxy.py +151 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_object_proxy_type_checks.py +150 -1
- wrapt-2.2.2rc3/tests/core/test_formatargspec_py35.py +0 -44
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/LICENSE +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/MANIFEST.in +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/README.md +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/RELEASE.rst +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/pyproject.toml +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/setup.cfg +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/setup.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt/__wrapt__.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt/arguments.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt/caching.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt/decorators.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt/importer.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt/patches.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt/signature.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt/synchronization.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt/weakrefs.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt.egg-info/dependency_links.txt +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt.egg-info/not-zip-safe +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt.egg-info/requires.txt +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/src/wrapt.egg-info/top_level.txt +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/compat.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/module1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/module2.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_adapter.py +0 -0
- /wrapt-2.2.2rc3/tests/core/test_adapter_py3.py → /wrapt-2.3.0.dev1/tests/core/test_adapter_annotations.py +0 -0
- /wrapt-2.2.2rc3/tests/core/test_adapter_py33.py → /wrapt-2.3.0.dev1/tests/core/test_adapter_kwonly.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_annotations.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_attribute_wrapper.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_callable_binding_no_args.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_callable_object_proxy.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_class.py +0 -0
- /wrapt-2.2.2rc3/tests/core/test_class_py37.py → /wrapt-2.3.0.dev1/tests/core/test_class_mro_entries.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_copy.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_decorator_state.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_decorators.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_deferred_patching.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_descriptor_get_class_access.py +0 -0
- /wrapt-2.2.2rc3/tests/core/test_descriptors_py36.py → /wrapt-2.3.0.dev1/tests/core/test_descriptors.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_enabled_bool_error.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_entry_points.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_function.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_function_wrapper.py +0 -0
- /wrapt-2.2.2rc3/tests/core/test_inheritance_py37.py → /wrapt-2.3.0.dev1/tests/core/test_inheritance.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_inner_classmethod.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_inner_staticmethod.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_inplace_operators.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_instancemethod.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_lazy_object_proxy.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_lru_cache.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_memoize.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_monkey_patching.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_nested_function.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_object_proxy_hook.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_object_proxy_self_dict.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_outer_classmethod.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_outer_staticmethod.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_pickle.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_post_import_hooks.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_pyerr_clear_propagation.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_resolve_path.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_runtime_type_hints.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_synchronized_async.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_synchronized_lock.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_synchronized_markers.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_type_module_attribute.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_update_attributes.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_weak_function_proxy.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/core/test_with_signature.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_auto_object_proxy_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_auto_object_proxy_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_decorator_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_decorator_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t2.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t2.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t3.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t3.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t4.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t4.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t5.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t5.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t6.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t6.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t7.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t7.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t8.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_cls_t8.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t2.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t2.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t3.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t3.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t4.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t4.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t5.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t5.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t6.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t6.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t7.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_function_wrapper_fn_t7.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_object_proxy_arithmetic_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_object_proxy_arithmetic_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_object_proxy_container_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_object_proxy_container_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_object_proxy_context_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_object_proxy_context_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_partial_callable_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_partial_callable_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_patch_function_wrapper_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_patch_function_wrapper_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_patching_primitives_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_patching_primitives_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_post_import_hooks_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_post_import_hooks_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_synchronized_lock_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_synchronized_lock_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_transient_function_wrapper_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_transient_function_wrapper_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_weak_function_proxy_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_weak_function_proxy_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t1.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t1.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t2.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t2.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t3.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t3.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t4.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t4.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t5.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t5.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t6.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t6.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t7.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t7.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t8.out +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tests/mypy/mypy_wrap_function_wrapper_t8.py +0 -0
- {wrapt-2.2.2rc3 → wrapt-2.3.0.dev1}/tox.ini +0 -0
|
@@ -2537,6 +2537,67 @@ static PyObject *WraptObjectProxy_round(WraptObjectProxyObject *self,
|
|
|
2537
2537
|
|
|
2538
2538
|
/* ------------------------------------------------------------------------- */
|
|
2539
2539
|
|
|
2540
|
+
static PyObject *wrapt_call_math_unary(WraptObjectProxyObject *self,
|
|
2541
|
+
const char *name)
|
|
2542
|
+
{
|
|
2543
|
+
PyObject *module = NULL;
|
|
2544
|
+
PyObject *function = NULL;
|
|
2545
|
+
PyObject *result = NULL;
|
|
2546
|
+
|
|
2547
|
+
if (!self->wrapped)
|
|
2548
|
+
{
|
|
2549
|
+
if (raise_uninitialized_wrapper_error(self) == -1)
|
|
2550
|
+
return NULL;
|
|
2551
|
+
}
|
|
2552
|
+
|
|
2553
|
+
module = PyImport_ImportModule("math");
|
|
2554
|
+
|
|
2555
|
+
if (!module)
|
|
2556
|
+
return NULL;
|
|
2557
|
+
|
|
2558
|
+
function = PyObject_GetAttrString(module, name);
|
|
2559
|
+
|
|
2560
|
+
if (!function)
|
|
2561
|
+
{
|
|
2562
|
+
Py_DECREF(module);
|
|
2563
|
+
return NULL;
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
Py_DECREF(module);
|
|
2567
|
+
|
|
2568
|
+
result = PyObject_CallFunctionObjArgs(function, self->wrapped, NULL);
|
|
2569
|
+
|
|
2570
|
+
Py_DECREF(function);
|
|
2571
|
+
|
|
2572
|
+
return result;
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2575
|
+
/* ------------------------------------------------------------------------- */
|
|
2576
|
+
|
|
2577
|
+
static PyObject *WraptObjectProxy_trunc(WraptObjectProxyObject *self,
|
|
2578
|
+
PyObject *Py_UNUSED(ignored))
|
|
2579
|
+
{
|
|
2580
|
+
return wrapt_call_math_unary(self, "trunc");
|
|
2581
|
+
}
|
|
2582
|
+
|
|
2583
|
+
/* ------------------------------------------------------------------------- */
|
|
2584
|
+
|
|
2585
|
+
static PyObject *WraptObjectProxy_floor(WraptObjectProxyObject *self,
|
|
2586
|
+
PyObject *Py_UNUSED(ignored))
|
|
2587
|
+
{
|
|
2588
|
+
return wrapt_call_math_unary(self, "floor");
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
/* ------------------------------------------------------------------------- */
|
|
2592
|
+
|
|
2593
|
+
static PyObject *WraptObjectProxy_ceil(WraptObjectProxyObject *self,
|
|
2594
|
+
PyObject *Py_UNUSED(ignored))
|
|
2595
|
+
{
|
|
2596
|
+
return wrapt_call_math_unary(self, "ceil");
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
/* ------------------------------------------------------------------------- */
|
|
2600
|
+
|
|
2540
2601
|
static PyObject *WraptObjectProxy_complex(WraptObjectProxyObject *self,
|
|
2541
2602
|
PyObject *args)
|
|
2542
2603
|
{
|
|
@@ -3148,6 +3209,9 @@ static PyMethodDef WraptObjectProxy_methods[] = {
|
|
|
3148
3209
|
{"__reversed__", (PyCFunction)WraptObjectProxy_reversed, METH_NOARGS, 0},
|
|
3149
3210
|
{"__round__", (PyCFunction)WraptObjectProxy_round,
|
|
3150
3211
|
METH_VARARGS | METH_KEYWORDS, 0},
|
|
3212
|
+
{"__trunc__", (PyCFunction)WraptObjectProxy_trunc, METH_NOARGS, 0},
|
|
3213
|
+
{"__floor__", (PyCFunction)WraptObjectProxy_floor, METH_NOARGS, 0},
|
|
3214
|
+
{"__ceil__", (PyCFunction)WraptObjectProxy_ceil, METH_NOARGS, 0},
|
|
3151
3215
|
{"__complex__", (PyCFunction)WraptObjectProxy_complex, METH_NOARGS, 0},
|
|
3152
3216
|
{"__mro_entries__", (PyCFunction)WraptObjectProxy_mro_entries,
|
|
3153
3217
|
METH_VARARGS | METH_KEYWORDS, 0},
|
|
@@ -62,6 +62,10 @@ def __wrapper_length_hint__(self):
|
|
|
62
62
|
return self.__wrapped__.__length_hint__()
|
|
63
63
|
|
|
64
64
|
|
|
65
|
+
def __wrapper_fspath__(self):
|
|
66
|
+
return self.__wrapped__.__fspath__()
|
|
67
|
+
|
|
68
|
+
|
|
65
69
|
def __wrapper_await__(self):
|
|
66
70
|
return (yield from self.__wrapped__.__await__())
|
|
67
71
|
|
|
@@ -120,6 +124,9 @@ class AutoObjectProxy(BaseObjectProxy):
|
|
|
120
124
|
if "__length_hint__" in wrapped_attrs and "__length_hint__" not in class_attrs:
|
|
121
125
|
namespace["__length_hint__"] = __wrapper_length_hint__
|
|
122
126
|
|
|
127
|
+
if "__fspath__" in wrapped_attrs and "__fspath__" not in class_attrs:
|
|
128
|
+
namespace["__fspath__"] = __wrapper_fspath__
|
|
129
|
+
|
|
123
130
|
# Note that not providing compatibility with generator-based coroutines
|
|
124
131
|
# (PEP 342) here as they are removed in Python 3.11+ and were deprecated
|
|
125
132
|
# in 3.8.
|
|
@@ -193,6 +200,12 @@ class AutoObjectProxy(BaseObjectProxy):
|
|
|
193
200
|
elif getattr(cls, "__length_hint__", None) is __wrapper_length_hint__:
|
|
194
201
|
delattr(cls, "__length_hint__")
|
|
195
202
|
|
|
203
|
+
if hasattr(self.__wrapped__, "__fspath__"):
|
|
204
|
+
if "__fspath__" not in class_attrs:
|
|
205
|
+
cls.__fspath__ = __wrapper_fspath__
|
|
206
|
+
elif getattr(cls, "__fspath__", None) is __wrapper_fspath__:
|
|
207
|
+
delattr(cls, "__fspath__")
|
|
208
|
+
|
|
196
209
|
if hasattr(self.__wrapped__, "__await__"):
|
|
197
210
|
if "__await__" not in class_attrs:
|
|
198
211
|
cls.__await__ = __wrapper_await__
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Core object proxy and function wrapper implementations."""
|
|
2
2
|
|
|
3
3
|
import inspect
|
|
4
|
+
import math
|
|
4
5
|
import operator
|
|
5
6
|
import sys
|
|
6
7
|
import types
|
|
@@ -164,7 +165,9 @@ class ObjectProxy(_ObjectProxyDictBase, metaclass=_ObjectProxyMetaType):
|
|
|
164
165
|
"""A transparent object proxy that delegates attribute access to a
|
|
165
166
|
wrapped object."""
|
|
166
167
|
|
|
167
|
-
|
|
168
|
+
@classmethod
|
|
169
|
+
def __class_getitem__(cls, item, /):
|
|
170
|
+
return types.GenericAlias(cls, item)
|
|
168
171
|
|
|
169
172
|
def __init__(self, wrapped):
|
|
170
173
|
"""Create an object proxy around the given object."""
|
|
@@ -261,6 +264,15 @@ class ObjectProxy(_ObjectProxyDictBase, metaclass=_ObjectProxyMetaType):
|
|
|
261
264
|
def __round__(self, ndigits=None):
|
|
262
265
|
return round(self.__wrapped__, ndigits)
|
|
263
266
|
|
|
267
|
+
def __trunc__(self):
|
|
268
|
+
return math.trunc(self.__wrapped__)
|
|
269
|
+
|
|
270
|
+
def __floor__(self):
|
|
271
|
+
return math.floor(self.__wrapped__)
|
|
272
|
+
|
|
273
|
+
def __ceil__(self):
|
|
274
|
+
return math.ceil(self.__wrapped__)
|
|
275
|
+
|
|
264
276
|
def __mro_entries__(self, bases):
|
|
265
277
|
if not isinstance(self.__wrapped__, type) and hasattr(
|
|
266
278
|
self.__wrapped__, "__mro_entries__"
|
|
@@ -749,7 +761,7 @@ class _FunctionWrapperBase(ObjectProxy):
|
|
|
749
761
|
object.__setattr__(self, "_self_parent", parent)
|
|
750
762
|
object.__setattr__(self, "_self_owner", owner)
|
|
751
763
|
|
|
752
|
-
def __get__(self, instance, owner):
|
|
764
|
+
def __get__(self, instance, owner=None):
|
|
753
765
|
# This method handles both unbound and bound derived wrapper classes.
|
|
754
766
|
# It is kept in the base class as the amount of common code makes it
|
|
755
767
|
# impractical to split into the derived classes.
|
|
@@ -2,7 +2,7 @@ import sys
|
|
|
2
2
|
|
|
3
3
|
if sys.version_info >= (3, 10):
|
|
4
4
|
from inspect import FullArgSpec, Signature
|
|
5
|
-
from types import ModuleType, TracebackType
|
|
5
|
+
from types import GenericAlias, ModuleType, TracebackType
|
|
6
6
|
from typing import (
|
|
7
7
|
Any,
|
|
8
8
|
AsyncIterator,
|
|
@@ -109,6 +109,7 @@ if sys.version_info >= (3, 10):
|
|
|
109
109
|
|
|
110
110
|
def __init__(self, wrapped: _T) -> None: ...
|
|
111
111
|
def __getattr__(self, name: str) -> Any: ...
|
|
112
|
+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
|
|
112
113
|
def __mro_entries__(self, bases: tuple[type, ...]) -> tuple[type, ...]: ...
|
|
113
114
|
|
|
114
115
|
# Context managers.
|
|
@@ -149,6 +150,9 @@ if sys.version_info >= (3, 10):
|
|
|
149
150
|
def __bytes__(self) -> bytes: ...
|
|
150
151
|
def __index__(self) -> int: ...
|
|
151
152
|
def __round__(self, ndigits: int | None = ..., /) -> Any: ...
|
|
153
|
+
def __trunc__(self) -> Any: ...
|
|
154
|
+
def __floor__(self) -> Any: ...
|
|
155
|
+
def __ceil__(self) -> Any: ...
|
|
152
156
|
|
|
153
157
|
# Unary arithmetic.
|
|
154
158
|
def __neg__(self) -> Any: ...
|
|
@@ -224,7 +228,8 @@ if sys.version_info >= (3, 10):
|
|
|
224
228
|
# and bitwise operations (e.g. __add__ returns
|
|
225
229
|
# ``self.__object_proxy__(self.__wrapped__ + other)``). Subclasses
|
|
226
230
|
# override it to control the type of proxy produced from operations.
|
|
227
|
-
|
|
231
|
+
@property
|
|
232
|
+
def __self_dict__(self) -> dict[str, Any]: ...
|
|
228
233
|
@property
|
|
229
234
|
def __object_proxy__(self) -> type[BaseObjectProxy[Any]]: ...
|
|
230
235
|
def __self_setattr__(self, name: str, value: Any) -> None: ...
|
|
@@ -260,6 +265,7 @@ if sys.version_info >= (3, 10):
|
|
|
260
265
|
def __aiter__(self) -> AsyncIterator[Any]: ...
|
|
261
266
|
async def __anext__(self) -> Any: ...
|
|
262
267
|
def __length_hint__(self) -> int: ...
|
|
268
|
+
def __fspath__(self) -> str | bytes: ...
|
|
263
269
|
def __await__(self) -> Generator[Any, Any, Any]: ...
|
|
264
270
|
|
|
265
271
|
# LazyObjectProxy
|
|
@@ -292,7 +298,7 @@ if sys.version_info >= (3, 10):
|
|
|
292
298
|
|
|
293
299
|
# PartialCallableObjectProxy
|
|
294
300
|
|
|
295
|
-
class PartialCallableObjectProxy:
|
|
301
|
+
class PartialCallableObjectProxy(BaseObjectProxy[Callable[..., Any]]):
|
|
296
302
|
def __init__(
|
|
297
303
|
self, func: Callable[..., Any], *args: Any, **kwargs: Any
|
|
298
304
|
) -> None: ...
|
|
@@ -304,7 +310,7 @@ if sys.version_info >= (3, 10):
|
|
|
304
310
|
|
|
305
311
|
# WeakFunctionProxy
|
|
306
312
|
|
|
307
|
-
class WeakFunctionProxy:
|
|
313
|
+
class WeakFunctionProxy(BaseObjectProxy[Callable[..., Any]]):
|
|
308
314
|
def __init__(
|
|
309
315
|
self,
|
|
310
316
|
wrapped: Callable[..., Any],
|
|
@@ -378,6 +384,12 @@ if sys.version_info >= (3, 10):
|
|
|
378
384
|
) -> BoundFunctionWrapper[_P1, _R1]: ...
|
|
379
385
|
|
|
380
386
|
class FunctionWrapper(_FunctionWrapperBase[_P1, _R1]):
|
|
387
|
+
# The class used to construct the bound wrapper when the function
|
|
388
|
+
# wrapper is bound to an instance via the descriptor protocol.
|
|
389
|
+
# Subclasses override it to control the type of bound wrapper
|
|
390
|
+
# produced.
|
|
391
|
+
__bound_function_wrapper__: type[BoundFunctionWrapper[_P1, _R1]]
|
|
392
|
+
|
|
381
393
|
def __init__(
|
|
382
394
|
self,
|
|
383
395
|
wrapped: _WrappedFunction[_P1, _R1],
|
|
@@ -644,7 +656,7 @@ if sys.version_info >= (3, 10):
|
|
|
644
656
|
|
|
645
657
|
# bind_state_to_wrapper()
|
|
646
658
|
|
|
647
|
-
class _StateBindingWrapper:
|
|
659
|
+
class _StateBindingWrapper(BaseObjectProxy[Any]):
|
|
648
660
|
name: str
|
|
649
661
|
wrapper_factory: _Descriptor | None
|
|
650
662
|
def __init__(self, *, name: str = "state") -> None: ...
|
|
@@ -30,28 +30,27 @@ tests/core/compat.py
|
|
|
30
30
|
tests/core/module1.py
|
|
31
31
|
tests/core/module2.py
|
|
32
32
|
tests/core/test_adapter.py
|
|
33
|
-
tests/core/
|
|
34
|
-
tests/core/
|
|
33
|
+
tests/core/test_adapter_annotations.py
|
|
34
|
+
tests/core/test_adapter_kwonly.py
|
|
35
35
|
tests/core/test_annotations.py
|
|
36
36
|
tests/core/test_attribute_wrapper.py
|
|
37
37
|
tests/core/test_auto_object_proxy.py
|
|
38
38
|
tests/core/test_callable_binding_no_args.py
|
|
39
39
|
tests/core/test_callable_object_proxy.py
|
|
40
40
|
tests/core/test_class.py
|
|
41
|
-
tests/core/
|
|
41
|
+
tests/core/test_class_mro_entries.py
|
|
42
42
|
tests/core/test_copy.py
|
|
43
43
|
tests/core/test_decorator_state.py
|
|
44
44
|
tests/core/test_decorators.py
|
|
45
45
|
tests/core/test_deferred_patching.py
|
|
46
46
|
tests/core/test_descriptor_get_class_access.py
|
|
47
|
-
tests/core/
|
|
47
|
+
tests/core/test_descriptors.py
|
|
48
48
|
tests/core/test_enabled_bool_error.py
|
|
49
49
|
tests/core/test_entry_points.py
|
|
50
|
-
tests/core/
|
|
51
|
-
tests/core/test_formatargspec_py38.py
|
|
50
|
+
tests/core/test_formatargspec.py
|
|
52
51
|
tests/core/test_function.py
|
|
53
52
|
tests/core/test_function_wrapper.py
|
|
54
|
-
tests/core/
|
|
53
|
+
tests/core/test_inheritance.py
|
|
55
54
|
tests/core/test_inner_classmethod.py
|
|
56
55
|
tests/core/test_inner_staticmethod.py
|
|
57
56
|
tests/core/test_inplace_operators.py
|
|
@@ -37,14 +37,8 @@ def construct_dummy(path, parent):
|
|
|
37
37
|
def pytest_pycollect_makemodule(module_path, parent):
|
|
38
38
|
basename = module_path.name
|
|
39
39
|
|
|
40
|
-
# Handle Python 2/3 general cases
|
|
41
|
-
if "_py2" in basename and version >= (3, 0):
|
|
42
|
-
return construct_dummy(module_path, parent)
|
|
43
|
-
if "_py3" in basename and version < (3, 0):
|
|
44
|
-
return construct_dummy(module_path, parent)
|
|
45
|
-
|
|
46
40
|
# Handle specific Python version cases using regex
|
|
47
|
-
# Match patterns like "
|
|
41
|
+
# Match patterns like "_py310", "_py312", etc.
|
|
48
42
|
version_match = re.search(r"_py(\d)(\d*)", basename)
|
|
49
43
|
if version_match:
|
|
50
44
|
major = int(version_match.group(1))
|
|
@@ -134,6 +134,41 @@ class TestAutoObjectProxy(unittest.TestCase):
|
|
|
134
134
|
|
|
135
135
|
self.assertEqual(asyncio.run(await_proxy()), 42)
|
|
136
136
|
|
|
137
|
+
def test_fspath(self):
|
|
138
|
+
import os
|
|
139
|
+
|
|
140
|
+
class PathLike:
|
|
141
|
+
def __fspath__(self):
|
|
142
|
+
return "/path/to/file"
|
|
143
|
+
|
|
144
|
+
base = wrapt.BaseObjectProxy(PathLike())
|
|
145
|
+
|
|
146
|
+
self.assertRaises(TypeError, os.fspath, base)
|
|
147
|
+
|
|
148
|
+
proxy = wrapt.AutoObjectProxy(PathLike())
|
|
149
|
+
|
|
150
|
+
self.assertEqual(os.fspath(proxy), "/path/to/file")
|
|
151
|
+
self.assertTrue(isinstance(proxy, os.PathLike))
|
|
152
|
+
|
|
153
|
+
def test_fspath_pathlib(self):
|
|
154
|
+
import os
|
|
155
|
+
import pathlib
|
|
156
|
+
|
|
157
|
+
instance = pathlib.PurePath("/path/to/file")
|
|
158
|
+
proxy = wrapt.AutoObjectProxy(instance)
|
|
159
|
+
|
|
160
|
+
self.assertEqual(os.fspath(proxy), os.fspath(instance))
|
|
161
|
+
self.assertTrue(isinstance(proxy, os.PathLike))
|
|
162
|
+
|
|
163
|
+
def test_fspath_not_pathlike(self):
|
|
164
|
+
import os
|
|
165
|
+
|
|
166
|
+
proxy = wrapt.AutoObjectProxy(42)
|
|
167
|
+
|
|
168
|
+
self.assertFalse(hasattr(type(proxy), "__fspath__"))
|
|
169
|
+
self.assertRaises(TypeError, os.fspath, proxy)
|
|
170
|
+
self.assertFalse(isinstance(proxy, os.PathLike))
|
|
171
|
+
|
|
137
172
|
def test_descriptor(self):
|
|
138
173
|
class Descriptor:
|
|
139
174
|
def __init__(self, value):
|
|
@@ -212,6 +247,24 @@ class TestAutoObjectProxyReassignment(unittest.TestCase):
|
|
|
212
247
|
proxy.__wrapped__ = object()
|
|
213
248
|
self.assertFalse(hasattr(proxy, "__iter__"))
|
|
214
249
|
|
|
250
|
+
def test_fspath_added_on_reassignment(self):
|
|
251
|
+
import os
|
|
252
|
+
import pathlib
|
|
253
|
+
|
|
254
|
+
proxy = wrapt.AutoObjectProxy(object())
|
|
255
|
+
self.assertRaises(TypeError, os.fspath, proxy)
|
|
256
|
+
proxy.__wrapped__ = pathlib.PurePath("/path/to/file")
|
|
257
|
+
self.assertEqual(os.fspath(proxy), os.fspath(proxy.__wrapped__))
|
|
258
|
+
|
|
259
|
+
def test_fspath_removed_on_reassignment(self):
|
|
260
|
+
import os
|
|
261
|
+
import pathlib
|
|
262
|
+
|
|
263
|
+
proxy = wrapt.AutoObjectProxy(pathlib.PurePath("/path/to/file"))
|
|
264
|
+
self.assertEqual(os.fspath(proxy), os.fspath(proxy.__wrapped__))
|
|
265
|
+
proxy.__wrapped__ = object()
|
|
266
|
+
self.assertRaises(TypeError, os.fspath, proxy)
|
|
267
|
+
|
|
215
268
|
def test_next_added_on_reassignment(self):
|
|
216
269
|
class Iterator:
|
|
217
270
|
def __iter__(self):
|
|
@@ -1,11 +1,50 @@
|
|
|
1
|
-
import sys
|
|
2
1
|
import unittest
|
|
3
2
|
from inspect import getfullargspec
|
|
4
3
|
|
|
5
4
|
from wrapt.arguments import formatargspec
|
|
6
5
|
|
|
7
6
|
|
|
8
|
-
class
|
|
7
|
+
class TestFormatargspec(unittest.TestCase):
|
|
8
|
+
|
|
9
|
+
def assertFormatEqual(self, func, ref):
|
|
10
|
+
formatted = formatargspec(*getfullargspec(func))
|
|
11
|
+
self.assertEqual(formatted, ref)
|
|
12
|
+
|
|
13
|
+
def test_formatargspec(self):
|
|
14
|
+
def foo1():
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
self.assertFormatEqual(foo1, "()")
|
|
18
|
+
|
|
19
|
+
def foo2(a, b="c"):
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
self.assertFormatEqual(foo2, ("(a, b='c')"))
|
|
23
|
+
|
|
24
|
+
def foo3(a, b, *args, **kwargs):
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
self.assertFormatEqual(foo3, "(a, b, *args, **kwargs)")
|
|
28
|
+
|
|
29
|
+
def foo4(a: int, b) -> list:
|
|
30
|
+
return []
|
|
31
|
+
|
|
32
|
+
formatted4 = "(a: int, b) -> list"
|
|
33
|
+
self.assertFormatEqual(foo4, formatted4)
|
|
34
|
+
|
|
35
|
+
# examples from https://www.python.org/dev/peps/pep-3102/
|
|
36
|
+
def sortwords(*wordlist, case_sensitive=False):
|
|
37
|
+
pass
|
|
38
|
+
|
|
39
|
+
self.assertFormatEqual(sortwords, "(*wordlist, case_sensitive=False)")
|
|
40
|
+
|
|
41
|
+
def compare(a, b, *, key=None):
|
|
42
|
+
pass
|
|
43
|
+
|
|
44
|
+
self.assertFormatEqual(compare, "(a, b, *, key=None)")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class TestFormatargspecPositionalOnly(unittest.TestCase):
|
|
9
48
|
|
|
10
49
|
def assertFormatEqual(self, func, ref):
|
|
11
50
|
formatted = formatargspec(*getfullargspec(func))
|
|
@@ -1973,6 +1973,157 @@ class SpecialMethods(unittest.TestCase):
|
|
|
1973
1973
|
self.assertEqual(round(instance, 3), round(proxy, 3))
|
|
1974
1974
|
self.assertEqual(round(instance, ndigits=3), round(proxy, ndigits=3))
|
|
1975
1975
|
|
|
1976
|
+
def test_math_integral_protocol_methods(self):
|
|
1977
|
+
import math
|
|
1978
|
+
|
|
1979
|
+
class Instance:
|
|
1980
|
+
def __trunc__(self):
|
|
1981
|
+
return "truncated"
|
|
1982
|
+
|
|
1983
|
+
def __floor__(self):
|
|
1984
|
+
return "floored"
|
|
1985
|
+
|
|
1986
|
+
def __ceil__(self):
|
|
1987
|
+
return "ceiled"
|
|
1988
|
+
|
|
1989
|
+
instance = Instance()
|
|
1990
|
+
proxy = wrapt.ObjectProxy(instance)
|
|
1991
|
+
|
|
1992
|
+
self.assertEqual(math.trunc(proxy), "truncated")
|
|
1993
|
+
self.assertEqual(math.floor(proxy), "floored")
|
|
1994
|
+
self.assertEqual(math.ceil(proxy), "ceiled")
|
|
1995
|
+
|
|
1996
|
+
def test_float_trunc(self):
|
|
1997
|
+
import math
|
|
1998
|
+
|
|
1999
|
+
instance = 1.7
|
|
2000
|
+
proxy = wrapt.ObjectProxy(instance)
|
|
2001
|
+
|
|
2002
|
+
self.assertEqual(math.trunc(instance), math.trunc(proxy))
|
|
2003
|
+
self.assertEqual(math.trunc(instance), 1)
|
|
2004
|
+
|
|
2005
|
+
def test_negative_float_trunc(self):
|
|
2006
|
+
import math
|
|
2007
|
+
|
|
2008
|
+
instance = -1.7
|
|
2009
|
+
proxy = wrapt.ObjectProxy(instance)
|
|
2010
|
+
|
|
2011
|
+
self.assertEqual(math.trunc(instance), math.trunc(proxy))
|
|
2012
|
+
self.assertEqual(math.trunc(instance), -1)
|
|
2013
|
+
|
|
2014
|
+
def test_fractions_trunc(self):
|
|
2015
|
+
import fractions
|
|
2016
|
+
import math
|
|
2017
|
+
|
|
2018
|
+
instance = fractions.Fraction("7/3")
|
|
2019
|
+
proxy = wrapt.ObjectProxy(instance)
|
|
2020
|
+
|
|
2021
|
+
self.assertEqual(math.trunc(instance), math.trunc(proxy))
|
|
2022
|
+
self.assertEqual(math.trunc(instance), 2)
|
|
2023
|
+
|
|
2024
|
+
def test_float_floor(self):
|
|
2025
|
+
import math
|
|
2026
|
+
|
|
2027
|
+
instance = 1.7
|
|
2028
|
+
proxy = wrapt.ObjectProxy(instance)
|
|
2029
|
+
|
|
2030
|
+
self.assertEqual(math.floor(instance), math.floor(proxy))
|
|
2031
|
+
self.assertEqual(math.floor(instance), 1)
|
|
2032
|
+
|
|
2033
|
+
def test_negative_float_floor(self):
|
|
2034
|
+
import math
|
|
2035
|
+
|
|
2036
|
+
instance = -1.7
|
|
2037
|
+
proxy = wrapt.ObjectProxy(instance)
|
|
2038
|
+
|
|
2039
|
+
self.assertEqual(math.floor(instance), math.floor(proxy))
|
|
2040
|
+
self.assertEqual(math.floor(instance), -2)
|
|
2041
|
+
|
|
2042
|
+
def test_fractions_floor(self):
|
|
2043
|
+
import fractions
|
|
2044
|
+
import math
|
|
2045
|
+
|
|
2046
|
+
instance = fractions.Fraction("7/3")
|
|
2047
|
+
proxy = wrapt.ObjectProxy(instance)
|
|
2048
|
+
|
|
2049
|
+
self.assertEqual(math.floor(instance), math.floor(proxy))
|
|
2050
|
+
self.assertEqual(math.floor(instance), 2)
|
|
2051
|
+
|
|
2052
|
+
def test_float_ceil(self):
|
|
2053
|
+
import math
|
|
2054
|
+
|
|
2055
|
+
instance = 1.7
|
|
2056
|
+
proxy = wrapt.ObjectProxy(instance)
|
|
2057
|
+
|
|
2058
|
+
self.assertEqual(math.ceil(instance), math.ceil(proxy))
|
|
2059
|
+
self.assertEqual(math.ceil(instance), 2)
|
|
2060
|
+
|
|
2061
|
+
def test_negative_float_ceil(self):
|
|
2062
|
+
import math
|
|
2063
|
+
|
|
2064
|
+
instance = -1.7
|
|
2065
|
+
proxy = wrapt.ObjectProxy(instance)
|
|
2066
|
+
|
|
2067
|
+
self.assertEqual(math.ceil(instance), math.ceil(proxy))
|
|
2068
|
+
self.assertEqual(math.ceil(instance), -1)
|
|
2069
|
+
|
|
2070
|
+
def test_fractions_ceil(self):
|
|
2071
|
+
import fractions
|
|
2072
|
+
import math
|
|
2073
|
+
|
|
2074
|
+
instance = fractions.Fraction("7/3")
|
|
2075
|
+
proxy = wrapt.ObjectProxy(instance)
|
|
2076
|
+
|
|
2077
|
+
self.assertEqual(math.ceil(instance), math.ceil(proxy))
|
|
2078
|
+
self.assertEqual(math.ceil(instance), 3)
|
|
2079
|
+
|
|
2080
|
+
def test_math_integral_protocol_methods_override_float(self):
|
|
2081
|
+
# The __floor__() and __ceil__() methods of the wrapped object must
|
|
2082
|
+
# take precedence over any __float__() fallback in math.floor() and
|
|
2083
|
+
# math.ceil(), the same as if the wrapped object was used directly.
|
|
2084
|
+
|
|
2085
|
+
import math
|
|
2086
|
+
|
|
2087
|
+
class Instance:
|
|
2088
|
+
def __float__(self):
|
|
2089
|
+
return 3.5
|
|
2090
|
+
|
|
2091
|
+
def __trunc__(self):
|
|
2092
|
+
return "truncated"
|
|
2093
|
+
|
|
2094
|
+
def __floor__(self):
|
|
2095
|
+
return "floored"
|
|
2096
|
+
|
|
2097
|
+
def __ceil__(self):
|
|
2098
|
+
return "ceiled"
|
|
2099
|
+
|
|
2100
|
+
instance = Instance()
|
|
2101
|
+
proxy = wrapt.ObjectProxy(instance)
|
|
2102
|
+
|
|
2103
|
+
self.assertEqual(math.trunc(proxy), math.trunc(instance))
|
|
2104
|
+
self.assertEqual(math.floor(proxy), math.floor(instance))
|
|
2105
|
+
self.assertEqual(math.ceil(proxy), math.ceil(instance))
|
|
2106
|
+
|
|
2107
|
+
def test_math_float_fallback(self):
|
|
2108
|
+
# An object which only provides __float__() still works with
|
|
2109
|
+
# math.floor() and math.ceil() via the proxy, the same as it does
|
|
2110
|
+
# when used directly, and math.trunc() fails the same way for both.
|
|
2111
|
+
|
|
2112
|
+
import math
|
|
2113
|
+
|
|
2114
|
+
class Instance:
|
|
2115
|
+
def __float__(self):
|
|
2116
|
+
return 3.5
|
|
2117
|
+
|
|
2118
|
+
instance = Instance()
|
|
2119
|
+
proxy = wrapt.ObjectProxy(instance)
|
|
2120
|
+
|
|
2121
|
+
self.assertEqual(math.floor(proxy), math.floor(instance))
|
|
2122
|
+
self.assertEqual(math.ceil(proxy), math.ceil(instance))
|
|
2123
|
+
|
|
2124
|
+
self.assertRaises(TypeError, math.trunc, instance)
|
|
2125
|
+
self.assertRaises(TypeError, math.trunc, proxy)
|
|
2126
|
+
|
|
1976
2127
|
|
|
1977
2128
|
class TestArgumentUnpacking(unittest.TestCase):
|
|
1978
2129
|
|