Tag

classmethod

1 views collected around this technical thread.

Python Programming Learning Circle
Python Programming Learning Circle
May 21, 2025 · Fundamentals

Why Defining __init__ Directly Is a Bad Practice and How to Replace It with dataclasses, classmethods, and NewType

The article explains that using a custom __init__ method to create data structures couples object construction with side‑effects, leading to fragile code, and demonstrates how refactoring with @dataclass, @classmethod factories and typing.NewType yields cleaner, safer, and more testable Python classes.

Pythonclassmethoddataclasses
0 likes · 13 min read
Why Defining __init__ Directly Is a Bad Practice and How to Replace It with dataclasses, classmethods, and NewType
Python Programming Learning Circle
Python Programming Learning Circle
May 6, 2025 · Fundamentals

Avoiding the __init__ Anti‑Pattern in Python: Using dataclasses, classmethods, and NewType

The article explains why defining custom __init__ methods for simple data structures is a bad practice in Python and proposes a modern solution using dataclasses, classmethod factories, and typing.NewType to create clear, testable, and type‑safe class interfaces.

Best PracticesPythonclassmethod
0 likes · 13 min read
Avoiding the __init__ Anti‑Pattern in Python: Using dataclasses, classmethods, and NewType
Test Development Learning Exchange
Test Development Learning Exchange
Aug 11, 2018 · Fundamentals

Understanding Python staticmethod and classmethod with Examples

This article explains Python's staticmethod and classmethod decorators, demonstrates their usage with concrete class examples, and shows how to apply static and class methods in a Date utility class for data validation and conversion.

classmethodfundamentalsprogramming
0 likes · 4 min read
Understanding Python staticmethod and classmethod with Examples