Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

README.md

Dunder Methods, Dataclass, slots, MRO, eq edge case

Dunder Methods

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def __str__(self):
        return f"({self.x}, {self.y})"
    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

Dataclass

from dataclasses import dataclass
@dataclass
class Item:
    name: str
    price: float

slots

class Slim:
    __slots__ = ['x', 'y']
    def __init__(self, x, y):
        self.x = x
        self.y = y

MRO

class A: pass
class B(A): pass
print(B.__mro__)

eq without hash (Edge Case)

class BadEq:
    def __eq__(self, other):
        return True
# hash(BadEq())  # TypeError: unhashable type