Skip to content

Instantly share code, notes, and snippets.

@amirsoroush
amirsoroush / dataclass_vs_namedtuple_vs_normalclass.py
Created May 20, 2023 21:37
Performance comparison between dataclass & namedtuple & regular classes
from dataclasses import dataclass
from time import perf_counter
from typing import NamedTuple
class Person:
def __init__(self, first_name: str, last_name: str, age: int) -> None:
self.first_name = first_name
self.last_name = last_name
self.age = age
@amirsoroush
amirsoroush / super_implementation.py
Last active November 2, 2023 20:28
Super() implementation in pure Python
import unittest
from inspect import isfunction, ismethod
def _get_attr(obj, name):
"""Bypass object's normal attribute look up with __getattribute__"""
return object.__getattribute__(obj, name)
class Super: