{"id":536,"library":"mypy-extensions","title":"Mypy Extensions","description":"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.","status":"active","version":"1.1.0","language":"python","source_language":"en","source_url":"https://github.com/python/mypy_extensions","tags":["type-checking","mypy","typing","type-hints","extensions","static-analysis"],"install":[{"cmd":"pip install mypy-extensions","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Provides extensions *for* the mypy type checker. While not a direct pip dependency, it's essential for this library's utility.","package":"mypy","optional":false},{"reason":"Extends the Python standard library's `typing` module.","package":"typing","optional":false}],"imports":[{"note":"While `typing.override` exists in Python 3.12+, `mypy_extensions.override` provides support for earlier Python versions when using mypy.","wrong":"from typing import override","symbol":"override","correct":"from mypy_extensions import override"},{"note":"For `TypedDict` keys, `mypy_extensions.Required` provides support for mypy, especially for Python versions older than 3.11 where `typing.Required` was introduced.","wrong":"from typing import Required","symbol":"Required","correct":"from mypy_extensions import Required"},{"note":"Similar to `Required`, `mypy_extensions.NotRequired` provides support for `TypedDict` optional keys in mypy for Python versions older than 3.11.","wrong":"from typing import NotRequired","symbol":"NotRequired","correct":"from mypy_extensions import NotRequired"}],"quickstart":{"code":"from mypy_extensions import override\nfrom typing import Dict, Any, List\n\nclass BaseAnalyzer:\n    def analyze(self, data: Dict[str, Any]) -> List[str]:\n        raise NotImplementedError\n\nclass SpecificAnalyzer(BaseAnalyzer):\n    @override\n    def analyze(self, data: Dict[str, Any]) -> List[str]:\n        if \"items\" in data:\n            return [str(item) for item in data[\"items\"]]\n        return []\n\n# Example usage for mypy checking\ndef process_data(analyzer: BaseAnalyzer, input_data: Dict[str, Any]) -> List[str]:\n    return analyzer.analyze(input_data)\n\nif __name__ == \"__main__\":\n    analyzer_instance = SpecificAnalyzer()\n    results = process_data(analyzer_instance, {\"items\": [1, \"two\", 3.0]})\n    print(f\"Analysis results: {results}\")\n\n# To type-check this file:\n# mypy your_file_name.py","lang":"python","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":"mypy >= 1.19"},{"fix":"Refactor advanced `Callable` type definitions to use callback protocols. Consult the mypy documentation on 'callback protocols' for migration guides.","message":"Mypy'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.","severity":"deprecated","affected_versions":"All versions, as this is a shift in mypy's recommended approach."},{"fix":"Avoid `non_interactive = True` when using IDE integrations. If necessary for specific CI/CD environments, ensure it's not enabled in development configurations.","message":"Setting `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.","severity":"gotcha","affected_versions":"All versions of mypy used with IDE integrations that rely on standard error output parsing."},{"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.","message":"Many 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.","severity":"gotcha","affected_versions":"All versions."}],"env_vars":null,"last_verified":"2026-05-12T14:45:35.790Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the package using pip: `pip install mypy-extensions` or `poetry add mypy-extensions` (if using Poetry), ensuring it's installed in the correct environment.","cause":"The 'mypy-extensions' package is not installed in the current Python environment or is not accessible in the runtime environment (e.g., when using Docker without installing dev dependencies).","error":"ModuleNotFoundError: No module named 'mypy_extensions'"},{"fix":"Import `TypedDict` from the standard `typing` module: `from typing import TypedDict`. For compatibility with older Python versions, use `from typing_extensions import TypedDict` or conditional imports.","cause":"You are attempting to import `TypedDict` from `mypy_extensions`, but for Python 3.8 and newer, `TypedDict` has been moved to the standard `typing` module. If `mypy-extensions` is installed but no longer exports `TypedDict` for your Python version, this error occurs.","error":"ImportError: cannot import name 'TypedDict' from 'mypy_extensions'"},{"fix":"Import `Literal` from the standard `typing` module: `from typing import Literal`. For compatibility with older Python versions, use `from typing_extensions import Literal` or conditional imports.","cause":"You are attempting to import `Literal` from `mypy_extensions`, but for Python 3.8 and newer, `Literal` has been moved to the standard `typing` module. If `mypy-extensions` is installed but no longer exports `Literal` for your Python version, this error occurs.","error":"ImportError: cannot import name 'Literal' from 'mypy_extensions'"}],"ecosystem":"pypi","meta_description":null,"install_score":0,"install_tag":"stale","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}