Skip to main content

8 posts tagged with "mypy"

mypy tag description

View All Tags

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.

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.

Mandatory Python hints Enforcement

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

This is a critical question for developers moving from dynamically-typed code to modern, type-hinted Python. The concise answer is: No, Python does not have mandatory type hints built into the language itself.

By default, the Python interpreter is dynamically typed and will ignore type hints entirely at runtime. However, you can make type hints mandatory and runtime-enforced by utilizing external tools and libraries.

The Python Type Hinting Paradox: Why it Doesn't Raise an Error

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

This is a fundamental and often confusing concept when developers transition to using static type checking in Python: Python's type hints are advisory, not mandatory.

The core reason why passing None to a function expecting a specific type like str or int does not raise an error at runtime (on entrance) is that the Python interpreter, by default, ignores type hints.

What is Mypy, How to Use It, and Why It Matters

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

Python is known for being a dynamically typed language - you don’t have to declare variable types, and everything works at runtime. But as your codebase grows, undetected type errors can creep in. That’s where Mypy comes in.

Mypy is a static type checker for Python. It checks your Python code for type errors without running it.