Tag

dataclasses

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
Code Mala Tang
Code Mala Tang
Mar 29, 2025 · Fundamentals

Better Ways to Handle Missing Values in Python Instead of Returning None

This article explains why returning None for missing values can cause unexpected errors in Python code and presents five practical alternatives—including default values, raising exceptions, special objects, type‑hinted optional returns, and dataclasses—to handle absent data safely and cleanly.

Pythondataclassesdefault values
0 likes · 4 min read
Better Ways to Handle Missing Values in Python Instead of Returning None
Code Mala Tang
Code Mala Tang
Jan 21, 2025 · Fundamentals

Master Python Classes: Inheritance, Composition, and Advanced OOP Techniques

This guide explores Python class fundamentals, covering inheritance versus composition, the use of super(), distinctions among instance, class, and static methods, dataclasses, the __dict__ attribute, name mangling, @property, dynamic class creation with type(), and __slots__ for attribute control.

ClassesOOPPython
0 likes · 9 min read
Master Python Classes: Inheritance, Composition, and Advanced OOP Techniques
Test Development Learning Exchange
Test Development Learning Exchange
Oct 16, 2024 · Fundamentals

Introduction to Python Libraries: attrs, bidict, Box, dataclasses, and DottedDict

This article introduces five Python libraries—attrs, bidict, Box, dataclasses, and DottedDict—explaining their installation, core features, and practical code examples for simplifying data class creation, bidirectional mapping, nested data access, and configuration management.

Pythonattrsbidict
0 likes · 10 min read
Introduction to Python Libraries: attrs, bidict, Box, dataclasses, and DottedDict
Test Development Learning Exchange
Test Development Learning Exchange
Jul 29, 2024 · Fundamentals

Leveraging Python dataclasses and typing for clean, type‑safe data models

This article explains how Python's dataclasses module, combined with the typing library, can automatically generate boilerplate methods, provide rich type annotations, support optional and union types, enable dictionary serialization, perform runtime checks, and be extended with field metadata for robust, maintainable code.

Serializationcode examplesdataclasses
0 likes · 6 min read
Leveraging Python dataclasses and typing for clean, type‑safe data models
Test Development Learning Exchange
Test Development Learning Exchange
Jun 24, 2024 · Fundamentals

Python Standard Library: 9 Essential Modules for Efficient Development

This article introduces nine powerful Python standard library modules that enhance code efficiency and readability, covering context management, iterators, concurrency, file operations, functional programming, AST parsing, type hints, data classes, and async programming.

ASTPythonasyncio
0 likes · 4 min read
Python Standard Library: 9 Essential Modules for Efficient Development
Python Programming Learning Circle
Python Programming Learning Circle
Nov 4, 2023 · Fundamentals

Modern Python Standard Library: pathlib, secrets, zoneinfo, dataclasses, logging, f‑strings, tomllib, and setuptools

This article reviews recent Python standard‑library enhancements, showing how pathlib replaces os.path, secrets supersedes os.urandom, zoneinfo replaces pytz, dataclasses improve on namedtuple, proper logging outperforms print, f‑strings beat format, tomllib replaces tomli, and setuptools supersedes distutils, with code examples for each.

dataclassesf-stringslogging
0 likes · 13 min read
Modern Python Standard Library: pathlib, secrets, zoneinfo, dataclasses, logging, f‑strings, tomllib, and setuptools
Python Programming Learning Circle
Python Programming Learning Circle
Jul 22, 2023 · Fundamentals

Modern Python Standard Library: Pathlib, Secrets, Zoneinfo, Dataclasses, Logging, f‑strings, Tomllib and Setuptools

This article reviews the most useful additions to the Python standard library—Pathlib, Secrets, Zoneinfo, Dataclasses, proper logging, f‑strings, Tomllib and Setuptools—explaining why they replace older modules, showing concise code examples, and offering guidance on adopting them in everyday projects.

PythonSecretsSetuptools
0 likes · 14 min read
Modern Python Standard Library: Pathlib, Secrets, Zoneinfo, Dataclasses, Logging, f‑strings, Tomllib and Setuptools
Python Programming Learning Circle
Python Programming Learning Circle
Jun 30, 2023 · Fundamentals

Modern Python Standard Library: Pathlib, Secrets, ZoneInfo, Dataclasses, Logging, f‑strings, Tomllib, and Setuptools

This article reviews several modern Python standard‑library modules—Pathlib, Secrets, ZoneInfo, Dataclasses, proper logging, f‑strings, Tomllib, and Setuptools—explaining why they replace older alternatives and providing concise code examples to help developers adopt best practices and keep their projects up‑to‑date.

dataclassesloggingpathlib
0 likes · 13 min read
Modern Python Standard Library: Pathlib, Secrets, ZoneInfo, Dataclasses, Logging, f‑strings, Tomllib, and Setuptools
Python Programming Learning Circle
Python Programming Learning Circle
Jun 3, 2023 · Fundamentals

Applying Rust‑Inspired Type Safety and Design Patterns to Python

The article explains how Rust’s strict type system and concepts such as type hints, dataclasses, algebraic data types, newtype, typestate patterns, and safer mutex designs can be adopted in Python to improve code robustness, readability, and maintainability.

Pythondataclassesdesign patterns
0 likes · 20 min read
Applying Rust‑Inspired Type Safety and Design Patterns to Python
Python Programming Learning Circle
Python Programming Learning Circle
Feb 21, 2023 · Fundamentals

New Python Standard Library Features: pathlib, secrets, zoneinfo, dataclasses, logging, f‑strings, tomllib, and setuptools

This article introduces the most useful additions and modern replacements in recent Python releases—including pathlib, the secrets module, zoneinfo, dataclasses, proper logging, f‑strings, the built‑in tomllib, and the transition from distutils to setuptools—showing why and how to adopt them in everyday code.

Pythondataclassesf-strings
0 likes · 15 min read
New Python Standard Library Features: pathlib, secrets, zoneinfo, dataclasses, logging, f‑strings, tomllib, and setuptools
Python Programming Learning Circle
Python Programming Learning Circle
Jan 17, 2022 · Fundamentals

Six Alternatives to Classes in Python

This article compares six Python alternatives to traditional classes—plain classes, tuples, dictionaries, named tuples, attrs, dataclasses, and Pydantic—examining their syntax, validation capabilities, mutability, string representation, JSON (de)serialization, memory usage, and performance to help developers choose the most suitable data‑modeling approach.

ClassesData ModelingPerformance
0 likes · 17 min read
Six Alternatives to Classes in Python
Python Programming Learning Circle
Python Programming Learning Circle
Oct 29, 2021 · Fundamentals

15 Concise Python Tips for Efficient Coding

This article presents fifteen practical Python techniques—including multi‑key sorting, data classes, list comprehensions, memory inspection, frequency analysis, attrs usage, dictionary merging, multiple return values, filtering, mapping, zipping, reversing, existence checks, flattening nested lists, and uniqueness testing—each illustrated with clear code examples and explanations.

Functionsdataclassesdictionary
0 likes · 15 min read
15 Concise Python Tips for Efficient Coding