I have a class defined in Python 2.7 like this:
from future.builtins import object
class Point(object):
def __init__(self, x, y):
self.x = x
self.y = y
In PyCharm, this gives a warning in the __init__
line:
Signature is not compatible to __new__.
I don't understand what this warning is telling me. Can someone give an example where this warning would rightfully catch an error or can this warning be turned off?
There's a PyCharm thread for this, but it doesn't help me: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000254530-PyCharm-init-Signature-is-not-compatible-to-new-
future.builtins
module I could find does not list anobject
in its API, so what exactly are you importing there? Do you get the same warning if you use the standardobject
? Anyway, the reason behind this warning is that if a class defines both__new__
and__init__
, they have to have compatible parameters, since the same parameters will normally be passed to both (the one exception being the obscure possibility that__new__()
returns an instance of an unrelated class). – Koerner__new__
. – Injudiciousobject
without need to import anything – Fritts__new__
, how is it supposed to know that it should accept argumentsx
andy
to be compatible with your__init__
? Like guidot wrote, you can use object to define new-style classes without importing anything. I suspect that your future import causes these problems. – Ryswick