diff --git a/MANIFEST.in b/MANIFEST.in index fa609f52e9a..7b55f2e515c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,6 +5,6 @@ include licenses/*.txt include requirements.txt recursive-include packaging *.py *.j2 recursive-include test/integration * -recursive-include test/sanity *.in *.json *.py *.txt *.ini +recursive-include test/sanity *.in *.json *.py *.pyi *.txt *.ini recursive-include test/support *.py *.ps1 *.psm1 *.cs *.md recursive-include test/units * diff --git a/lib/ansible/galaxy/collection/__init__.py b/lib/ansible/galaxy/collection/__init__.py index 9633b6b690a..433af9f5efa 100644 --- a/lib/ansible/galaxy/collection/__init__.py +++ b/lib/ansible/galaxy/collection/__init__.py @@ -41,8 +41,8 @@ else: HAS_PACKAGING = True try: - from distlib.manifest import Manifest # type: ignore[import] - from distlib import DistlibException # type: ignore[import] + from distlib.manifest import Manifest + from distlib import DistlibException except ImportError: HAS_DISTLIB = False else: diff --git a/test/sanity/code-smell/mypy/_type_stubs/distlib/__init__.pyi b/test/sanity/code-smell/mypy/_type_stubs/distlib/__init__.pyi new file mode 100644 index 00000000000..04a64762b4d --- /dev/null +++ b/test/sanity/code-smell/mypy/_type_stubs/distlib/__init__.pyi @@ -0,0 +1,5 @@ +# NOTE: `distlib` is untyped as of 10 Oct 2025. +# NOTE: This should be removed once types are upstream. +# Ref: https://github.com/pypa/distlib/pull/195 + +class DistlibException(Exception): ... diff --git a/test/sanity/code-smell/mypy/_type_stubs/distlib/manifest.pyi b/test/sanity/code-smell/mypy/_type_stubs/distlib/manifest.pyi new file mode 100644 index 00000000000..4adaa5785c2 --- /dev/null +++ b/test/sanity/code-smell/mypy/_type_stubs/distlib/manifest.pyi @@ -0,0 +1,8 @@ +# NOTE: `distlib` is untyped as of 10 Oct 2025. +# NOTE: This should be removed once types are upstream. +# Ref: https://github.com/pypa/distlib/pull/195 + +class Manifest: + def __init__(self, base: str | None = ...) -> None: ... + def process_directive(self, directive: str) -> None: ... + def sorted(self, wantdirs: bool = ...) -> list[str]: ... diff --git a/test/sanity/code-smell/mypy/ansible-core.ini b/test/sanity/code-smell/mypy/ansible-core.ini index 24414954c69..9a965e80798 100644 --- a/test/sanity/code-smell/mypy/ansible-core.ini +++ b/test/sanity/code-smell/mypy/ansible-core.ini @@ -13,6 +13,8 @@ strict_optional = False # See: https://github.com/python/mypy/issues/4717 disable_error_code = attr-defined,safe-super,type-abstract +mypy_path = ${MYPY_CONFIG_FILE_DIR}/_type_stubs + # Some controller unit tests use ansible_collections imports, both real and test-specific. # The real imports are not currently visible to mypy. # There's little point in exposing the test-specific imports.