Private helper. Checks if ``cls`` has an attribute named ``method_name`` and returns it only if it is a pure python function.
(cls, method_name, *, follow_wrapper_chains=True)
| 1915 | |
| 1916 | |
| 1917 | def _signature_get_user_defined_method(cls, method_name, *, follow_wrapper_chains=True): |
| 1918 | """Private helper. Checks if ``cls`` has an attribute |
| 1919 | named ``method_name`` and returns it only if it is a |
| 1920 | pure python function. |
| 1921 | """ |
| 1922 | if method_name == '__new__': |
| 1923 | meth = getattr(cls, method_name, None) |
| 1924 | else: |
| 1925 | meth = getattr_static(cls, method_name, None) |
| 1926 | if meth is None: |
| 1927 | return None |
| 1928 | |
| 1929 | # NOTE: The meth may wraps a non-user-defined callable. |
| 1930 | # In this case, we treat the meth as non-user-defined callable too. |
| 1931 | # (e.g. cls.__new__ generated by @warnings.deprecated) |
| 1932 | unwrapped_meth = None |
| 1933 | if follow_wrapper_chains: |
| 1934 | unwrapped_meth = unwrap(meth, stop=(lambda m: hasattr(m, "__signature__") |
| 1935 | or _signature_is_builtin(m))) |
| 1936 | |
| 1937 | if (isinstance(meth, _NonUserDefinedCallables) |
| 1938 | or isinstance(unwrapped_meth, _NonUserDefinedCallables)): |
| 1939 | # Once '__signature__' will be added to 'C'-level |
| 1940 | # callables, this check won't be necessary |
| 1941 | return None |
| 1942 | if method_name != '__new__': |
| 1943 | meth = _descriptor_get(meth, cls) |
| 1944 | return meth |
| 1945 | |
| 1946 | |
| 1947 | def _signature_get_partial(wrapped_sig, partial, extra_args=()): |
no test coverage detected
searching dependent graphs…