This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: "TypeError" can give a misleading message
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: markon, r.david.murray
Priority: normal Keywords:

Created on 2012-06-17 15:39 by markon, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg163072 - (view) Author: Marco Buccini (markon) Date: 2012-06-17 15:39
Suppose that you have an instance method that takes 2 arguments: one is required, while the other is a keyword argument. 

If you call that method without passing the required argument, but instead you only set the keyword argument, then you will get a TypeError exception, claiming this ...
 -> TypeError: 'method' takes at least 2 arguments (2 given)

(I am referring to this particular method: http://www.voidspace.org.uk/python/mock/mock.html#mock.Mock.mock_add_spec)

@patch('xyz.subprocess.Popen')
def test_xyz(self, mocked_popen):
    mocked_popen.mock_add_spec(spec_set=True)

I think the right error message should be different, in particular should be this:
 -> TypeError: 'method' takes at least 2 arguments (1 given)
msg163073 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-06-17 15:43
This is fixed in Python3:

>>> def foo(a, b=None):
...   pass
... 
>>> foo(b=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() missing 1 required positional argument: 'a'
History
Date User Action Args
2022-04-11 14:57:31adminsetgithub: 59303
2012-06-17 15:43:49r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg163073

resolution: out of date
stage: resolved
2012-06-17 15:39:27markoncreate