Skip to main content

6 posts tagged with "mypy"

mypy tag description

View All Tags

MyPy vs. Pyright: A Comprehensive Guide to Python Static Type Checkers

· 6 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

To maintain clean and bug-free codebases in large Python projects, static type checking is essential. The two primary static type checkers in the modern Python ecosystem are MyPy (the reference implementation) and Pyright (a fast, TypeScript-based checker developed by Microsoft).

While both tools parse type hints to identify errors before runtime, they differ in their implementation languages, performance profiles, library extensibility, and strictness. This guide provides a detailed comparison of MyPy and Pyright, analyzing their architectural trade-offs, behavioral differences, and how to combine them into a single workflow.

Mypy Ignore Cheat Sheet: Strategic Error Suppression in Python

· 7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

When integrating static type checking into dynamic or legacy Python projects, you will inevitably encounter situations where Mypy flags type mismatches that you cannot or should not refactor immediately.

Instead of disabling type checking globally, you should use Mypy's built-in error suppression mechanisms. Suppressing errors should be done with the narrowest possible scope. This cheat sheet details when and how to apply line-level comments, module configuration blocks, decorators, and global settings.

MyPy Configuration for Strict Typing

· 7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

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
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

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.

Python Type Hinting: Static Checkers (Mypy, Pyright) and Runtime Enforcement

· 7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Python is dynamically typed by default. While this allows for rapid prototyping and flexibility, it can lead to undetected type errors in production as codebases grow. To combat this, PEP 484 introduced type hints.

However, type hints are advisory by default. To make them mandatory, you must use static type checkers (which scan code before execution) or runtime validators (which intercept code execution).

This guide details how Python handles type hints, compares the two major static type checkers (Mypy and Pyright), and explains how to enforce type constraints at runtime using Pydantic, Beartype, and Typeguard.