TypeError: object .__ new __ (int) is not safe, use int .__ new __ ()

When reading this: What is a metaclass in Python? I am studying using __new__ with the following snippet: -

 class a(object): pass a.__new__(int,'abcdef',(int,),{}) 

There may be a problem when calling __new__ with a. . But, I get the following error, the meaning of which I do not understand: -

TypeError: object.__new__(int) is not safe, use int.__new__()

If something has to do with using __new__ , I can change that by reading some books. But can someone explain why this message is coming:

object.__new__(int) is not safe, use int.__new__()

+4
source share
1 answer

Simply put, before 2.6 - object.__new__ ignored arguments ... Now he can do something with them ... Therefore, the warning is that something else could happen.

This post Any ideas on better work for __new__ that lose their argument? - contains a much more detailed explanation.

You probably also want to check out http://docs.python.org/library/functions.html#type

Knowing what is possible with all the metafiles in Python is wonderful, but as a warning, I would not be too dependent on this, as I saw some really smart solutions that are just monsters ...

+2
source

Source: https://habr.com/ru/post/1440496/


All Articles