Skip to content

Commit ba5f2e0

Browse files
authored
Allow types-foo to depend on foo (#159)
1 parent 38a063d commit ba5f2e0

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

stub_uploader/metadata.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
import os
66
import re
77
import tarfile
8+
import tempfile
89
import urllib.parse
910
from collections.abc import Generator, Iterable
1011
from glob import glob
1112
from pathlib import Path
12-
import tempfile
1313
from typing import Any, Optional
1414

1515
import requests
1616
import tomli
1717
from packaging.requirements import Requirement
18-
from packaging.specifiers import Specifier, InvalidSpecifier
18+
from packaging.specifiers import InvalidSpecifier, Specifier
1919

2020
from .const import META, THIRD_PARTY_NAMESPACE, TYPES_PREFIX, UPLOADED_PATH
2121

@@ -348,11 +348,12 @@ def verify_external_req_stubs_require_its_runtime(
348348
# broken by new releases of upstream packages, even if they do not match the version spec we
349349
# have for the upstream distribution.
350350

351-
runtime_req_name = EXTERNAL_RUNTIME_REQ_MAP.get(req.name, req.name)
352-
353-
if not runtime_in_upstream_requires(
354-
req, data
355-
) and not runtime_in_upstream_sdist_requires(req, data):
351+
if not (
352+
req.name == upstream_distribution # Allow `types-foo` to require `foo`
353+
or runtime_in_upstream_requires(req, data)
354+
or runtime_in_upstream_sdist_requires(req, data)
355+
):
356+
runtime_req_name = EXTERNAL_RUNTIME_REQ_MAP.get(req.name, req.name)
356357
raise InvalidRequires(
357358
f"Expected dependency {runtime_req_name} to be listed in {upstream_distribution}'s "
358359
+ "requires_dist or the sdist's *.egg-info/requires.txt"

tests/test_integration.py

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def test_verify_external_req() -> None:
8282
verify_external_req(
8383
Requirement("mypy-extensions"), "mypy", _unsafe_ignore_allowlist=True
8484
)
85+
# Check that types-foo can depend on foo
86+
verify_external_req(Requirement("setuptools"), "setuptools")
8587

8688
with pytest.raises(
8789
InvalidRequires, match="to be present in the stub_uploader allowlist"

0 commit comments

Comments
 (0)