Skip to content

wvlab/example-python-module-protocols

Repository files navigation

module as protocol implementation

Python's structural subtyping allows any object, including a module, to satisfy a Protocol.

This repository tests this specific feature. We define a simple protocol and a module with a function that matches the protocol's signature. We then attempt to use this module where an object conforming to the protocol is expected.

structure

  • src/example_module_protocols/behavior.py: Defines the Proto protocol.
  • src/example_module_protocols/implementations/bar.py: A simple module that acts as an implicit implementation of Proto.
  • src/example_module_protocols/main.py: The main script that consumes the bar module.
  • run_type_checkers.sh: A convenience script to run Mypy, Pyright, Pyrefly, and Ty, making it easy to compare their outputs.

prerequisites

  • uv

steps to reproduce

uv sync --frozen
source .venv/bin/activate
./run_type_checkers.sh

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published