Closed ssbarnea closed 2 months ago
Welcome to this project and thank you!' first issue
Is my understanding correct that mypy wants some kind of marker to allow static type checking of the package?
I see that warning comes from Ansible, so that suggests Mkdocs lives in an industrialized deployment environment.
Consider that I don't know everything about this field. Could I ask you to give me more context, so that I better understand why py.typed
is important, and what problem it solves in your specific case?
@fralau This scenario occurs when a developer has mkdocs-macros-plugin
installed in their own environment, and uses mypy
to analyze not only their own source code but also any installed/imported packages found in the project environment (in this case it seems to be a project called mkdocs_ansible
, but the issue has nothing to do with Ansible. It is related to how mypy
in general behaves when it comes to analyzing dependencies in any Python project).
The warning will be raised by mypy
when it encounters a package that does not declare that it has type hints. This can be declared in a number of ways, one of them being to include a file called py.typed
in the package. See the following page for instructions on how to do so, making your package compliant to the PEP 561 standard:
https://mypy.readthedocs.io/en/stable/installed_packages.html#creating-pep-561-compatible-packages
As the page above says:
If you would like to publish a library package to a package repository yourself (e.g. on PyPI) for either internal or external use in type checking, packages that supply type information via type comments or annotations in the code should put a py.typed file in their package directory. For example, here is a typical directory structure:
setup.py package_a/ __init__.py lib.py py.typed
When adding the package, mypy complains about missing type marker.
This can easily be sorted by just adding the
py.typed
inside the package, even before the full types are adopted by the project.