I am a PyCharm newbie but a long-time IntelliJ user. In IntelliJ, when you are writing a class definition, the IDE can automatically generate a constructor, equals()
method, and hashCode()
method based on the instance variables. This is good not just for saving typing, but for preventing inadvertent errors and for automatically throwing in some equals()
and hashCode()
best practices.
I was hoping PyCharm could do the same, given that the products are from the same company. After much Googling and scouring of the documentation, I couldn't find anything for __eq__()
or __hash__()
. Granted, Python instance variables are not explicitly specified, but I was hoping the generator could follow a convention like offering all __init()__
parameters as potential instance variables. As for __init__()
, I found something that will automatically add instance variable settings into the __init__()
, but this approach seems more cumbersome than just typing, and it doesn't even add the instance variables as parameters to the __init__()
signature.
Am I missing anything in the documentation, or perhaps there is a plugin that can do this?
Update: to be clear, I am looking for something that generates the actual implementations of these methods. That is, if I had a class called Point
, and PyCharm knows my class has x
and y
instance variables, then it would automatically generate this for the __eq__()
method:
def __eq__(self, other):
if not isinstance(other, Point):
return NotImplemented
elif self is other:
return True
else:
return self.x == other.x and self.y == other.y
The equivalent is easily done in IntelliJ.