Skip to content

Commit 3a339b0

Browse files
authored
CI: Freeze DRF commit used in typecheck_tests and types-requests/types-urllib3 (#345)
* Freeze DRF git commit hash used in CI. * Freeze versions of types-requests and types-urllib3 since they are already incompatible with mypy 0.991. typecheck_tests.py runs in CI. It makes a git checkout of the django-rest-framework (DRF) project and then runs mypy over its test suite together with our stubs. The idea is that DRF test suite provides some example code that we can verify our type stubs against. Since upstream's test suite doesn't have proper type hints, there are bound to be lots of false positives where mypy's inference doesn't guess the intent of the developer, or hacks were made for testing purposes. So we have a massive IGNORED_ERRORS dict containing the false positives. Since we took the latest master state of DRF repo, as upstream adds new tests, new false positives would appear at a random moment in some djangorestframework-stubs pull request and we'd have to look into them and usually add new ignores.
1 parent 4fb7adf commit 3a339b0

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ pytest==7.2.1
55
pytest-mypy-plugins==1.10.1
66
djangorestframework==3.14.0
77
types-pytz==2022.7.1.0
8+
types-requests==2.28.11.8
9+
types-urllib3==1.26.25.4
810
django-stubs==1.13.0
911
django-stubs-ext==0.7.0
1012
-e .[compatible-mypy,coreapi,markdown]

scripts/git_helpers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from pathlib import Path
21
from typing import Optional
32

43
from git import RemoteProgress, Repo
@@ -14,7 +13,7 @@ def update(self, op_code, cur_count, max_count=None, message=""):
1413
print(self._cur_line)
1514

1615

17-
def checkout_target_tag(drf_version: Optional[str]) -> Path:
16+
def git_checkout_drf(commit_ref: Optional[str] = None) -> None:
1817
if not DRF_SOURCE_DIRECTORY.exists():
1918
DRF_SOURCE_DIRECTORY.mkdir(exist_ok=True, parents=False)
2019
repository = Repo.clone_from(
@@ -27,4 +26,4 @@ def checkout_target_tag(drf_version: Optional[str]) -> Path:
2726
else:
2827
repository = Repo(DRF_SOURCE_DIRECTORY)
2928
repository.remote("origin").pull("master", progress=ProgressPrinter(), depth=100)
30-
repository.git.checkout(drf_version or "master")
29+
repository.git.checkout(commit_ref or "master")

scripts/stubgen-drf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from mypy.stubgen import generate_stubs, parse_options
55

6-
from scripts.git_helpers import checkout_target_tag
6+
from scripts.git_helpers import git_checkout_drf
77
from scripts.paths import DRF_SOURCE_DIRECTORY
88

99
if __name__ == "__main__":
@@ -12,6 +12,6 @@
1212
args = parser.parse_args()
1313
if DRF_SOURCE_DIRECTORY.exists():
1414
shutil.rmtree(DRF_SOURCE_DIRECTORY)
15-
checkout_target_tag(args.drf_version)
15+
git_checkout_drf(args.drf_version)
1616
stubgen_options = parse_options([f"{DRF_SOURCE_DIRECTORY}", "-o=stubgen"])
1717
generate_stubs(stubgen_options)

scripts/typecheck_tests.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
from distutils import dir_util, spawn
88
from typing import Dict, List, Pattern, Union
99

10-
from scripts.git_helpers import checkout_target_tag
10+
from scripts.git_helpers import git_checkout_drf
1111
from scripts.paths import DRF_SOURCE_DIRECTORY, PROJECT_DIRECTORY, STUBS_DIRECTORY
1212

13+
# django-rest-framework commit hash to check against (ignored with --drf_version)
14+
# This should be updated periodically or after every DRF release.
15+
DRF_GIT_REF = "22d206c1e0dbc03840c4d190f7eda537c0f2010a"
16+
1317
IGNORED_MODULES = []
1418
MOCK_OBJECTS = [
1519
"MockQueryset",
@@ -284,7 +288,7 @@ def update(self, op_code, cur_count, max_count=None, message=""):
284288
parser = ArgumentParser()
285289
parser.add_argument("--drf_version", required=False)
286290
args = parser.parse_args()
287-
checkout_target_tag(args.drf_version)
291+
git_checkout_drf(args.drf_version or DRF_GIT_REF)
288292
if sys.version_info[1] > 7:
289293
shutil.copytree(STUBS_DIRECTORY, DRF_SOURCE_DIRECTORY / "rest_framework", dirs_exist_ok=True)
290294
else:

0 commit comments

Comments
 (0)