Skip to main content

MyPy vs. Pyright

· 6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

MyPy and Pyright are the two most powerful static type checkers currently used in the Python ecosystem. While both aim to enforce type hints and catch errors before runtime, they differ significantly in their implementation, philosophy, speed, and feature set.

Choosing between them—or deciding how to use them together—depends heavily on your priorities: speed, strictness, or integration with development environments.

How to Ignore Specific MyPy Errors

· 6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

Ignoring errors with MyPy should be a precise, surgical process, not a broad suppression. The most effective way to handle known, persistent issues (like dynamically assigned attributes or known type inconsistencies in third-party libraries) is by using the # type: ignore comment combined with the exact MyPy Error Code.

An experienced developer always aims for the narrowest possible scope of suppression to maintain maximum type-checking coverage across the rest of the codebase.

How to MyPy Ignore Errors Strategically

· 8 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

When integrating MyPy into a large or legacy Python codebase, or when dealing with highly dynamic code, you will inevitably encounter situations where MyPy raises valid errors that you cannot (or should not) fix immediately. In these cases, selectively ignoring errors becomes a vital skill.

A super experienced developer never ignores errors blindly; they use these mechanisms strategically to maintain the highest possible type-checking quality in the rest of the codebase.

Here is a deep dive into the various methods MyPy provides for ignoring errors, from the narrowest to the broadest scope.

Dataclass AttributeError Solutions

· 9 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

The AttributeError is one of the most common exceptions in Python, indicating an attempt to access or set a class attribute that simply doesn't exist. When it occurs within the context of a @dataclass, it often points to a misunderstanding of how the decorator automatically generates methods like __init__ and __setattr__.

Here is a breakdown of the most frequent AttributeError scenarios involving dataclasses and the high-level solutions to resolve them.

Benchmarking Dataclasses, Named Tuples, and Pydantic Models: Choosing the Right Python Data Structure

· 7 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

When structuring immutable, simple data in Python, developers often choose between several tools. While Dataclasses and Pydantic models dominate modern usage, older structures like namedtuple and simpler tools like tuple and dict still have niche uses.

This article compares these common data structures based on their primary function, mutability, and performance characteristics to help you choose the best tool for the job.

Pydantic vs. Dataclasses speed comparison

· 6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

While both Pydantic models and Python dataclasses serve to structure data, their performance characteristics are significantly different. The key distinction lies in when and how validation occurs. Dataclasses rely on simple Python object initialization, while Pydantic executes a comprehensive validation and coercion pipeline on every instantiation.

The clear winner in terms of raw execution speed is the Python Dataclass.

MyPy Configuration for Strict Typing

· 7 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

MyPy is the premier static type checker for Python. While running MyPy with no configuration works, achieving true, robust type safety requires a configuration that enables strict mode and specifically targets potential weak points in Python's type system.

This article details the essential settings within the mypy.ini, pyproject.toml, or setup.cfg file that an experienced developer uses to maximize type checking effectiveness.

Dataclasses vs. Pydantic model

· 6 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

The modern Python landscape offers two excellent tools for defining structured data: Dataclasses (introduced in Python 3.7) and Pydantic (a third-party library). While both help define classes for data, their core purpose, performance characteristics, and feature sets are fundamentally different.

Choosing between them depends on whether your primary need is simple data structuring (Dataclasses) or input validation and parsing (Pydantic).

Drawbacks of Pydantic: A Deep Dive with Examples

· 7 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

📉 Drawbacks of Pydantic: A Deep Dive with Examples

Pydantic is an indispensable tool in the modern Python ecosystem, powering frameworks like FastAPI and widely used for data validation. However, like any powerful abstraction, it comes with trade-offs. While it excels at validation and developer ergonomics, it introduces overhead and complexity that can become problematic in specific high-performance or dynamic scenarios.

This article explores the drawbacks of Pydantic, providing concrete code examples to illustrate where it might not be the best fit.

if-else Fail Fast pattern in Python

· 7 min read
Serhii Hrekov
software engineer, creator, artist, programmer, projects founder

The concept of "fail fast" is a fundamental principle in software engineering, rooted in the idea of handling erroneous conditions immediately at the entrance of a function or code block. From the perspective of a high-level Python developer, this technique, often applied using if/return patterns, is key to writing clean, readable, and maintainable code.

Here is an analysis of best practices, techniques to master, and patterns to strictly avoid when working with conditional logic.

Looking for more content?
Hrekov Blog contains 240 articles. Browse the blog archive or Explore the full timeline.