mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-12-25 13:53:48 +01:00
implement __eq__, __str__, __repr__ and __hash__ for Python data classes when it's possible
This commit is contained in:
parent
d08fb1da6e
commit
9710ff4e30
@ -15,6 +15,19 @@ class state:
|
|||||||
self.number = number
|
self.number = number
|
||||||
self.multiplicity = multiplicity
|
self.multiplicity = multiplicity
|
||||||
self.symmetry = symmetry
|
self.symmetry = symmetry
|
||||||
|
|
||||||
|
def __eq__(self, __o: object) -> bool:
|
||||||
|
return type(__o) is state and __o.number == self.number and __o.multiplicity == self.multiplicity and __o.symmetry == self.symmetry
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f'{self.number} ^{self.multiplicity}{self.symmetry}'
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f'{self.__class__.__name__}: {self.__str__()}'
|
||||||
|
|
||||||
|
def __hash__(self) -> int:
|
||||||
|
return hash((self.number, self.multiplicity, self.symmetry))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fromString(string):
|
def fromString(string):
|
||||||
m=re.match(r"^(?P<number>\d)\s*\^(?P<multiplicity>\d)(?P<sym>\S*)",string)
|
m=re.match(r"^(?P<number>\d)\s*\^(?P<multiplicity>\d)(?P<sym>\S*)",string)
|
||||||
@ -52,9 +65,18 @@ class exSet(object):
|
|||||||
self.name=name
|
self.name=name
|
||||||
self.index=index
|
self.index=index
|
||||||
|
|
||||||
def __str__(self):
|
def __eq__(self, __o: object) -> bool:
|
||||||
|
return type(__o) is exSet and __o.name == self.name and __o.index == self.index
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
return f"{self.name},{self.index}"
|
return f"{self.name},{self.index}"
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f'{self.__class__.__name__}: {self.__str__()}'
|
||||||
|
|
||||||
|
def __hash__(self) -> int:
|
||||||
|
return hash((self.name, self.index))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fromString(string):
|
def fromString(string):
|
||||||
vals = string.split(",")
|
vals = string.split(",")
|
||||||
@ -143,6 +165,7 @@ class dataFileBase(object):
|
|||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
return handler.readFromTable(table)
|
return handler.readFromTable(table)
|
||||||
|
|
||||||
def getMetadata(self):
|
def getMetadata(self):
|
||||||
dic=OrderedDict()
|
dic=OrderedDict()
|
||||||
dic["Molecule"]=self.molecule
|
dic["Molecule"]=self.molecule
|
||||||
@ -248,6 +271,18 @@ class method:
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.basis=args[0] if len(args)>0 else None
|
self.basis=args[0] if len(args)>0 else None
|
||||||
|
|
||||||
|
def __eq__(self, __o: object) -> bool:
|
||||||
|
return type(__o) is method and __o.name == self.name and __o.basis == self.basis
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.name + f'/{self.basis}' if self.basis!=None else ''
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f'{self.__class__.__name__}: {self.__str__()}'
|
||||||
|
|
||||||
|
def __hash__(self) -> int:
|
||||||
|
return hash((self.name, self.basis))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fromString(string):
|
def fromString(string):
|
||||||
vals = string.split(",")
|
vals = string.split(",")
|
||||||
@ -271,6 +306,18 @@ class code:
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.version = version
|
self.version = version
|
||||||
|
|
||||||
|
def __eq__(self, __o: object) -> bool:
|
||||||
|
return type(__o) is method and __o.name == self.name and __o.version == self.version
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.name + f'/{self.version}' if self.version!=None else ''
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
return f'{self.__class__.__name__}: {self.__str__()}'
|
||||||
|
|
||||||
|
def __hash__(self) -> int:
|
||||||
|
return hash((self.name, self.basis))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fromString(string):
|
def fromString(string):
|
||||||
vals = string.split(",")
|
vals = string.split(",")
|
||||||
|
Loading…
Reference in New Issue
Block a user