Registry / type-stubs / mypy-extensions

mypy-extensions

JSON →
library1.1.0pypypiunverified

mypy-extensions provides specific type system extensions for programs checked with the mypy type checker and the mypyc compiler. It acts as a bridge for experimental or mypy-specific typing features that may eventually be standardized in Python's `typing` module or `typing_extensions`, but are supported early by mypy. The library follows mypy's active development and releases are tied to mypy's needs, which typically sees multiple releases per month for the main mypy project.

type-stubstesting
pip install mypy-extensions
Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
3/5 runs
3/5 runs
py 3.11
3/5 runs
3/5 runs
py 3.12
3/5 runs
3/5 runs
py 3.13
3/5 runs
3/5 runs
py 3.9
3/5 runs
3/5 runs
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

override
from mypy_extensions import override
from mypy_extensions import override

This quickstart demonstrates the use of the `override` decorator from `mypy_extensions`. Run `mypy your_file_name.py` to type-check this example. If `SpecificAnalyzer.analyze` did not correctly override `BaseAnalyzer.analyze`, mypy would report an error. Note that for Python 3.12+, `typing.override` should generally be preferred if `mypy-extensions` is not otherwise needed. The core functionality of `mypy-extensions` is to provide types for mypy to check, not to execute specific runtime logic itself.

from mypy_extensions import override from typing import Dict, Any, List class BaseAnalyzer: def analyze(self, data: Dict[str, Any]) -> List[str]: raise NotImplementedError class SpecificAnalyzer(BaseAnalyzer): @override def analyze(self, data: Dict[str, Any]) -> List[str]: if "items" in data: return [str(item) for item in data["items"]] return [] # Example usage for mypy checking def process_data(analyzer: BaseAnalyzer, input_data: Dict[str, Any]) -> List[str]: return analyzer.analyze(input_data) if __name__ == "__main__": analyzer_instance = SpecificAnalyzer() results = process_data(analyzer_instance, {"items": [1, "two", 3.0]}) print(f"Analysis results: {results}") # To type-check this file: # mypy your_file_name.py
Debug
Known issues
breakingThe main `mypy` type checker, which `mypy-extensions` supports, has removed support for targeting Python 3.8 and now requires `--python-version 3.9` or greater. This means that while `mypy-extensions` 1.1.0 itself requires Python >=3.8, using `mypy` on projects targeting Python 3.8 with these extensions will lead to issues.
fix
Ensure your project targets Python 3.9 or newer when using recent versions of mypy. Update your `pyproject.toml` or `mypy.ini` with `python_version = 3.9` or higher.
affects: mypy >= 1.19
deprecatedMypy's 'Extended Callable types', which provided advanced ways to specify keyword and optional arguments in `Callable` types (and were historically a motivation for such extensions), are now deprecated. Users should migrate to 'callback protocols' instead.
fix
Refactor advanced `Callable` type definitions to use callback protocols. Consult the mypy documentation on 'callback protocols' for migration guides.
affects: All versions, as this is a shift in mypy's recommended approach.
gotchaSetting `non_interactive = True` in your `mypy.ini` or `setup.cfg` can silently prevent the Visual Studio Code Mypy extension (and potentially other IDE integrations) from displaying type checking errors in the editor, even though `mypy` itself reports them in its raw output.
fix
Avoid `non_interactive = True` when using IDE integrations. If necessary for specific CI/CD environments, ensure it's not enabled in development configurations.
affects: All versions of mypy used with IDE integrations that rely on standard error output parsing.
gotchaMany types initially provided by `mypy_extensions` (e.g., `TypedDict`, `Literal`, `Protocol`, `TypeGuard`, `Unpack`, `Required`, `NotRequired`, `override`) have since been moved into the standard library `typing` module or `typing_extensions` for broader compatibility across Python versions. Importing from `mypy_extensions` when `typing` or `typing_extensions` suffices can lead to unnecessary dependencies or confusion.
fix
Prioritize imports from `typing` (for your target Python version) first, then `typing_extensions`, and finally `mypy_extensions` only for mypy-specific features or for backporting types to older Python versions where `typing_extensions` doesn't cover them. Regularly refactor imports to use `typing` once types are standardized.
affects: All versions.
Upgrade
Version history
1.1.0latest on PyPI
Audit
Dependencies
mypyrequiredProvides extensions *for* the mypy type checker. While not a direct pip dependency, it's essential for this library's utility.
typingrequiredExtends the Python standard library's `typing` module.
Agent activity
40 hits · last 30 days
node
8
bytedance
6
seranking-bot
3
ahrefsbot
2
Amazon
1
Resources