Message355665
| Author |
terry.reedy |
| Recipients |
BTaskaya, Simon.Chopin, georg.brandl, terry.reedy, tshepang, xdegaye |
| Date |
2019年10月29日.18:12:48 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1572372768.41.0.308607852532.issue14196@roundup.psfhosted.org> |
| In-reply-to |
| Content |
Batuhan, thanks for the nudge. For the record ...
If __new__ were a normal instance method, then 'some_class.__new__()' would be a correct call, as 'some_class' would be passed to '__new__' as its first and perhaps only argument. But " __new__() is a static method (special-cased so you need not declare it as such)".
https://docs.python.org/3/reference/datamodel.html#object.__new__
Its special-casing makes it easy to forget that its first argument, a class, must be passed explicitly. Hence Xavier's comment.
In current 2.7.17 and 3.8 (for instance), with pdb left out of the picture, the missing cls argument results in
TypeError: object.__new__(): not enough arguments
When I pdb.run('A()') new and step, it catches the error and refuses to advance.
> <pyshell#10>(3)__new__()
(Pdb) s
TypeError: object.__new__(): not enough arguments
> <pyshell#10>(3)__new__() |
|