Fix failing staticmethod tests if they are inherited (#8205)
* Fix failing staticmethod tests if they are inherited * add comments, set default=None
This commit is contained in:
parent
7585221d55
commit
48c9a96a03
1
AUTHORS
1
AUTHORS
|
@ -29,6 +29,7 @@ Andy Freeland
|
|||
Anthon van der Neut
|
||||
Anthony Shaw
|
||||
Anthony Sottile
|
||||
Anton Grinevich
|
||||
Anton Lodder
|
||||
Antony Lee
|
||||
Arel Cordero
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fixed failing staticmethod test cases if they are inherited from a parent test class.
|
|
@ -163,7 +163,12 @@ def getfuncargnames(
|
|||
# it's passed as an unbound method or function, remove the first
|
||||
# parameter name.
|
||||
if is_method or (
|
||||
cls and not isinstance(cls.__dict__.get(name, None), staticmethod)
|
||||
# Not using `getattr` because we don't want to resolve the staticmethod.
|
||||
# Not using `cls.__dict__` because we want to check the entire MRO.
|
||||
cls
|
||||
and not isinstance(
|
||||
inspect.getattr_static(cls, name, default=None), staticmethod
|
||||
)
|
||||
):
|
||||
arg_names = arg_names[1:]
|
||||
# Remove any names that will be replaced with mocks.
|
||||
|
|
|
@ -59,6 +59,20 @@ def test_getfuncargnames_staticmethod():
|
|||
assert getfuncargnames(A.static, cls=A) == ("arg1", "arg2")
|
||||
|
||||
|
||||
def test_getfuncargnames_staticmethod_inherited() -> None:
|
||||
"""Test getfuncargnames for inherited staticmethods (#8061)"""
|
||||
|
||||
class A:
|
||||
@staticmethod
|
||||
def static(arg1, arg2, x=1):
|
||||
raise NotImplementedError()
|
||||
|
||||
class B(A):
|
||||
pass
|
||||
|
||||
assert getfuncargnames(B.static, cls=B) == ("arg1", "arg2")
|
||||
|
||||
|
||||
def test_getfuncargnames_partial():
|
||||
"""Check getfuncargnames for methods defined with functools.partial (#5701)"""
|
||||
import functools
|
||||
|
|
Loading…
Reference in New Issue