Mypy Zope Plugin

1.0.14 · active · verified Thu Apr 16

mypy-zope is a plugin for Mypy that provides type checking support for projects utilizing Zope interfaces (`zope.interface`). It allows Mypy to correctly understand and validate code that implements or interacts with Zope interfaces. The current version is 1.0.14, with releases occurring periodically to support newer Mypy versions and address issues.

Common errors

Warnings

Install

Imports

Quickstart

To get started, install `mypy-zope` and ensure `mypy` is also installed. Then, create a `mypy.ini` configuration file in your project root and add `plugins = mypy_zope.plugin` under the `[mypy]` section. Write some Python code that uses `zope.interface`, and then run `mypy` on your files. The plugin will enable Mypy to understand interface implementations and usage.

# 1. Create a mypy.ini file in your project root:
# [mypy]
# plugins = mypy_zope.plugin
# python_version = 3.9 # or your project's Python version

# 2. Create a Python file, e.g., my_app.py:
# from zope.interface import Interface, implementer

# class IGreeter(Interface):
#     def greet(name: str) -> str:
#         """Greets the given name."""

# @implementer(IGreeter)
# class HelloGreeter:
#     def greet(self, name: str) -> str:
#         return f"Hello, {name}!"

# def use_greeter(greeter: IGreeter) -> None:
#     print(greeter.greet("World"))

# use_greeter(HelloGreeter())

# 3. Run mypy from your terminal:
# mypy my_app.py

# Expected output for the above example (no errors if configured correctly):
# Success: no issues found in 1 source file

view raw JSON →