Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Bugs

[issue15098] "TypeError" can give a misleading message

 

 

Python bugs RSS feed   Index | Next | Previous | View Threaded


report at bugs

Jun 17, 2012, 8:39 AM

Post #1 of 2 (34 views)
Permalink
[issue15098] "TypeError" can give a misleading message

New submission from Marco Buccini <marcusbu [at] gmail>:

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)

----------
components: Interpreter Core
messages: 163072
nosy: markon
priority: normal
severity: normal
status: open
title: "TypeError" can give a misleading message
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15098>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com


report at bugs

Jun 17, 2012, 8:43 AM

Post #2 of 2 (32 views)
Permalink
[issue15098] "TypeError" can give a misleading message [In reply to]

R. David Murray <rdmurray [at] bitdance> added the comment:

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'

----------
nosy: +r.david.murray
resolution: -> out of date
stage: -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report [at] bugs>
<http://bugs.python.org/issue15098>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com

Python bugs RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.