forked from loafle/openapi-generator-original
[Python] Improve model equality implementation (#4663)
* [Python] Improve model equality implementation The model equality implementation template blindly tried accessing the `__dict__` attribute of the variable to compare equality against. This attribute does not exist for a lot of Python built-in types (`None`, `str` etc.) and the equality check would simply crash. This adds a simple guard to only continue with equality check if the variable to compare is an instance of the model being compared against. * Remove wrong auto-update of Python requirements
This commit is contained in:
@@ -127,6 +127,9 @@ class AdditionalPropertiesClass(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, AdditionalPropertiesClass):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -129,6 +129,9 @@ class Animal(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Animal):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -81,6 +81,9 @@ class AnimalFarm(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, AnimalFarm):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -151,6 +151,9 @@ class ApiResponse(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ApiResponse):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -103,6 +103,9 @@ class ArrayOfArrayOfNumberOnly(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ArrayOfArrayOfNumberOnly):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -103,6 +103,9 @@ class ArrayOfNumberOnly(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ArrayOfNumberOnly):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -151,6 +151,9 @@ class ArrayTest(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ArrayTest):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -225,6 +225,9 @@ class Capitalization(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Capitalization):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -153,6 +153,9 @@ class Cat(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Cat):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -127,6 +127,9 @@ class Category(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Category):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -103,6 +103,9 @@ class ClassModel(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ClassModel):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -103,6 +103,9 @@ class Client(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Client):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -153,6 +153,9 @@ class Dog(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Dog):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -140,6 +140,9 @@ class EnumArrays(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, EnumArrays):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -81,6 +81,9 @@ class EnumClass(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, EnumClass):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -193,6 +193,9 @@ class EnumTest(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, EnumTest):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -425,6 +425,9 @@ class FormatTest(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, FormatTest):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -127,6 +127,9 @@ class HasOnlyReadOnly(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, HasOnlyReadOnly):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -103,6 +103,9 @@ class List(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, List):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -134,6 +134,9 @@ class MapTest(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, MapTest):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -151,6 +151,9 @@ class MixedPropertiesAndAdditionalPropertiesClass(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, MixedPropertiesAndAdditionalPropertiesClass):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -127,6 +127,9 @@ class Model200Response(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Model200Response):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -103,6 +103,9 @@ class ModelReturn(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ModelReturn):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -177,6 +177,9 @@ class Name(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Name):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -103,6 +103,9 @@ class NumberOnly(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, NumberOnly):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -231,6 +231,9 @@ class Order(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Order):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -81,6 +81,9 @@ class OuterEnum(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, OuterEnum):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -235,6 +235,9 @@ class Pet(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Pet):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -127,6 +127,9 @@ class ReadOnlyFirst(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, ReadOnlyFirst):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -103,6 +103,9 @@ class SpecialModelName(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, SpecialModelName):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -127,6 +127,9 @@ class Tag(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, Tag):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
@@ -273,6 +273,9 @@ class User(object):
|
||||
"""
|
||||
Returns true if both objects are equal
|
||||
"""
|
||||
if not isinstance(other, User):
|
||||
return False
|
||||
|
||||
return self.__dict__ == other.__dict__
|
||||
|
||||
def __ne__(self, other):
|
||||
|
||||
Reference in New Issue
Block a user