Skip to content

Commit 066da4d

Browse files
authored
Add Pep561 tests for stub-only package with namespace packages (#11141)
This only adds tests that show the current behavior when we provide a stub-only package for a subpackage of a namespace package Proposals for behavior changes exist in python/typeshed#5800 Real world example is the `protobuf` package which installs to `google.protobuf` and the `types-protobuf` package which installs to `google-stubs/protobuf` (where `google` is a namespace package)
1 parent df827c9 commit 066da4d

File tree

19 files changed

+88
-17
lines changed

19 files changed

+88
-17
lines changed

mypy/test/testmodulefinder.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ def test__packages_with_ns(self) -> None:
184184
("ns_pkg_untyped.b.c", ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS),
185185
("ns_pkg_untyped.a.a_var", ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS),
186186

187+
# Namespace package without stub package
188+
("ns_pkg_w_stubs", self.path("ns_pkg_w_stubs")),
189+
("ns_pkg_w_stubs.typed", self.path("ns_pkg_w_stubs-stubs", "typed", "__init__.pyi")),
190+
("ns_pkg_w_stubs.typed_inline",
191+
self.path("ns_pkg_w_stubs", "typed_inline", "__init__.py")),
192+
("ns_pkg_w_stubs.untyped", ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS),
193+
187194
# Regular package with py.typed
188195
("pkg_typed", self.path("pkg_typed", "__init__.py")),
189196
("pkg_typed.a", self.path("pkg_typed", "a.py")),
@@ -239,6 +246,13 @@ def test__packages_without_ns(self) -> None:
239246
("ns_pkg_untyped.b.c", ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS),
240247
("ns_pkg_untyped.a.a_var", ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS),
241248

249+
# Namespace package without stub package
250+
("ns_pkg_w_stubs", ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS),
251+
("ns_pkg_w_stubs.typed", ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS),
252+
("ns_pkg_w_stubs.typed_inline",
253+
self.path("ns_pkg_w_stubs", "typed_inline", "__init__.py")),
254+
("ns_pkg_w_stubs.untyped", ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS),
255+
242256
# Regular package with py.typed
243257
("pkg_typed", self.path("pkg_typed", "__init__.py")),
244258
("pkg_typed.a", self.path("pkg_typed", "a.py")),

test-data/packages/modulefinder-site-packages/ns_pkg_w_stubs/typed_inline/__init__.py

Whitespace-only changes.

test-data/packages/modulefinder-site-packages/ns_pkg_w_stubs/typed_inline/py.typed

Whitespace-only changes.

test-data/packages/modulefinder-site-packages/ns_pkg_w_stubs/untyped/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from setuptools import setup, find_packages
1+
from setuptools import setup
22

33
setup(
44
name='typedpkg_namespace.alpha',
55
version='1.0.0',
6-
packages=find_packages(),
76
namespace_packages=['typedpkg_ns'],
87
zip_safe=False,
9-
package_data={'typedpkg_ns.ns': ['py.typed']}
8+
package_data={'typedpkg_ns.a': ['py.typed']},
9+
packages=['typedpkg_ns.a'],
1010
)

test-data/packages/typedpkg_ns_a/typedpkg_ns/a/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)