Author xtreak
Recipients cbelu, cjw296, mariocj89, michael.foord, xtreak
Date 2019-03-31.17:07:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I am slightly concerned if spec should gain more responsibility than just validating attribute access which is mentioned in the docs. With the linked PR spec below would also validate the signature which is not done in Python 3.7 so this might break code for someone who only wants to validate access attribute access and not signature of the methods. It seems the PR also adds autospec argument to Mock that is currently not supported though spec and spec_set are supported.

from unittest import mock

def foo(lish):

mock_foo = mock.Mock(spec=foo)
mock_foo(1, 2)

except AttributeError:
    print("raises AttributeError for non-existent attribute")

# 3.7

➜  cpython git:(pr_1982) python3.7 /tmp/
raises AttributeError for non-existent attribute

# With PR

➜  cpython git:(pr_1982) ./python.exe /tmp/
Traceback (most recent call last):
  File "/tmp/", line 7, in <module>
    mock_foo(1, 2)
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/unittest/", line 1009, in __call__
    _mock_self._mock_check_sig(*args, **kwargs)
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/unittest/", line 103, in checksig
    sig.bind(*args, **kwargs)
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/", line 3016, in bind
    return args[0]._bind(args[1:], kwargs)
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/", line 2937, in _bind
    raise TypeError('too many positional arguments') from None
TypeError: too many positional arguments
Date User Action Args
2019-03-31 17:07:42xtreaksetrecipients: + xtreak, cjw296, michael.foord, mariocj89, cbelu
2019-03-31 17:07:42xtreaksetmessageid: <>
2019-03-31 17:07:42xtreaklinkissue30587 messages
2019-03-31 17:07:41xtreakcreate