Skip to content

Commit 0bb1182

Browse files
authored
Fix CI (#1108)
* Fix CI * Fix CI * Fix CI * Fix CI * APply black * APply black * Fix mypy * Fix mypy errors in django-stubs * Fix format * Fix plugin * Do not patch builtins by default * Fix mypy * Only run mypy on 3.10 for now * Only run mypy on 3.10 for now * WHAT THE HELL * Enable strict mode in mypy * Enable strict mode in mypy * Fix tests * Fix tests * Debug * Debug * Fix tests * Fix tests * Add TYPE_CHECKING debug * Caching maybe? * Caching maybe? * Try explicit `${{ matrix.python-version }}` * Remove debug * Fix typing * Finally
1 parent d2bfd37 commit 0bb1182

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+224
-583
lines changed

.github/workflows/release-django-stubs-ext.yml

Lines changed: 0 additions & 78 deletions
This file was deleted.

.github/workflows/release-django-stubs.yml

Lines changed: 0 additions & 76 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,40 @@ jobs:
2727
- name: Run pre-commit
2828
run: pre-commit install && pre-commit run --all-files
2929

30+
mypy-self-check:
31+
runs-on: ubuntu-latest
32+
strategy:
33+
matrix:
34+
python-version: ['3.7', '3.8', '3.9', '3.10']
35+
steps:
36+
- uses: actions/checkout@v3
37+
- name: Set up Python ${{ matrix.python-version }}
38+
uses: actions/setup-python@v4
39+
with:
40+
python-version: ${{ matrix.python-version }}
41+
- name: Install dependencies
42+
run: |
43+
pip install -U pip setuptools wheel
44+
pip install -r ./requirements.txt
45+
46+
- name: Run mypy on plugin code
47+
run: mypy --strict mypy_django_plugin
48+
49+
- name: Run mypy on ext code
50+
run: mypy --strict django_stubs_ext
51+
- name: Run mypy on scripts and utils
52+
run: mypy --strict scripts
53+
# TODO: run this check on versions, not only 3.10
54+
- name: Run mypy on stubs
55+
if: ${{ matrix.python-version }} == '3.10'
56+
run: |
57+
mypy --cache-dir=/dev/null --no-incremental django-stubs
58+
3059
test:
3160
runs-on: ubuntu-latest
3261
strategy:
3362
matrix:
34-
python-version: ['3.8']
63+
python-version: ['3.9']
3564
steps:
3665
- uses: actions/checkout@v3
3766
- name: Setup system dependencies
@@ -46,7 +75,7 @@ jobs:
4675
pip install -r ./requirements.txt
4776
4877
- name: Run tests
49-
run: pytest --mypy-ini-file=mypy.ini
78+
run: PYTHONPATH='.' pytest
5079

5180
typecheck:
5281
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@ repos:
1616
rev: v2.37.3
1717
hooks:
1818
- id: pyupgrade
19-
args: ["--py36-plus"]
20-
- repo: https://github.com/pre-commit/mirrors-isort
21-
rev: v5.10.1
19+
args: ["--py37-plus"]
20+
- repo: https://github.com/pycqa/isort
21+
rev: 5.10.1
2222
hooks:
2323
- id: isort
2424
name: isort (python)
25-
args: ["--profile", "black"]
2625
- id: isort
2726
name: isort (pyi)
2827
types: [pyi]
29-
args: ["--profile", "black"]
3028
- repo: https://github.com/psf/black
3129
rev: 22.6.0
3230
hooks:
@@ -35,19 +33,3 @@ repos:
3533
rev: 3.9.2
3634
hooks:
3735
- id: flake8
38-
- repo: local
39-
hooks:
40-
- id: mypy
41-
name: mypy
42-
entry: mypy
43-
language: system
44-
types: [ python ]
45-
exclude: "scripts/|django_stubs_ext/"
46-
args: [ "--config=mypy.ini", "--cache-dir=/dev/null", "--no-incremental" ]
47-
- id: mypy
48-
name: mypy (django_stubs_ext)
49-
entry: mypy
50-
language: system
51-
types: [ python ]
52-
files: "django_stubs_ext/|django_stubs_ext/tests/"
53-
args: [ "--config=mypy.ini", "--cache-dir=/dev/null", "--no-incremental", "--strict" ]

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ This happens because these Django classes do not support [`__class_getitem__`](h
116116

117117
Note: This monkey patching approach will only work when using Python 3.7 and higher, when the `__class_getitem__` magic method was introduced.
118118

119+
You can add extra types to patch with `django_stubs_ext.monkeypatch(extra_classes=[YourDesiredType])`
120+
119121
2. You can use strings instead: `'QuerySet[MyModel]'` and `'Manager[MyModel]'`, this way it will work as a type for `mypy` and as a regular `str` in runtime.
120122

121123
### How can I create a HttpRequest that's guaranteed to have an authenticated user?

django-stubs/contrib/admin/helpers.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from typing import Any, Callable, Dict, Iterable, Iterator, List, Mapping, Optional, Sequence, Tuple, Union
32

43
from django import forms
@@ -10,11 +9,7 @@ from django.forms.models import ModelForm
109
from django.forms.utils import ErrorDict, ErrorList
1110
from django.forms.widgets import Media, Widget
1211
from django.utils.safestring import SafeString
13-
14-
if sys.version_info < (3, 8):
15-
from typing_extensions import TypedDict
16-
else:
17-
from typing import TypedDict
12+
from typing_extensions import TypedDict
1813

1914
ACTION_CHECKBOX_NAME: str
2015

django-stubs/contrib/admin/options.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from typing import (
32
Any,
43
Callable,
@@ -43,11 +42,7 @@ from django.template.response import _TemplateForResponseT
4342
from django.urls.resolvers import URLPattern
4443
from django.utils.datastructures import _ListOrTuple
4544
from django.utils.safestring import SafeString
46-
47-
if sys.version_info < (3, 8):
48-
from typing_extensions import Literal, TypedDict
49-
else:
50-
from typing import Literal, TypedDict
45+
from typing_extensions import Literal, TypedDict
5146

5247
IS_POPUP_VAR: str
5348
TO_FIELD_VAR: str

django-stubs/contrib/admin/utils.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import datetime
2-
import sys
32
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Set, Tuple, Type, Union, overload
43
from uuid import UUID
54

@@ -15,11 +14,7 @@ from django.forms.forms import BaseForm
1514
from django.forms.formsets import BaseFormSet
1615
from django.http.request import HttpRequest
1716
from django.utils.datastructures import _IndexableCollection
18-
19-
if sys.version_info < (3, 8):
20-
from typing_extensions import Literal
21-
else:
22-
from typing import Literal
17+
from typing_extensions import Literal
2318

2419
class FieldIsAForeignKeyColumnName(Exception): ...
2520

django-stubs/contrib/admin/views/main.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Type, Union
32

43
from django.contrib.admin.filters import ListFilter
@@ -11,11 +10,7 @@ from django.db.models.options import Options
1110
from django.db.models.query import QuerySet
1211
from django.forms.formsets import BaseFormSet
1312
from django.http.request import HttpRequest
14-
15-
if sys.version_info < (3, 8):
16-
from typing_extensions import Literal
17-
else:
18-
from typing import Literal
13+
from typing_extensions import Literal
1914

2015
ALL_VAR: str
2116
ORDER_VAR: str

django-stubs/contrib/auth/base_user.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import sys
21
from typing import Any, List, Optional, Tuple, TypeVar, Union, overload
32

43
from django.db import models
54
from django.db.models.base import Model
65
from django.db.models.expressions import Combinable
76
from django.db.models.fields import BooleanField
8-
9-
if sys.version_info < (3, 8):
10-
from typing_extensions import Literal
11-
else:
12-
from typing import Literal
7+
from typing_extensions import Literal
138

149
_T = TypeVar("_T", bound=Model)
1510

django-stubs/contrib/auth/models.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
from typing import Any, Iterable, Optional, Set, Tuple, Type, TypeVar, Union
32

43
from django.contrib.auth.base_user import AbstractBaseUser as AbstractBaseUser
@@ -8,11 +7,7 @@ from django.contrib.contenttypes.models import ContentType
87
from django.db import models
98
from django.db.models.base import Model
109
from django.db.models.manager import EmptyManager
11-
12-
if sys.version_info < (3, 8):
13-
from typing_extensions import Literal
14-
else:
15-
from typing import Literal
10+
from typing_extensions import Literal
1611

1712
_AnyUser = Union[Model, "AnonymousUser"]
1813

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from django.core import validators
1+
from django.core.validators import RegexValidator
22

3-
class ASCIIUsernameValidator(validators.RegexValidator): ...
4-
class UnicodeUsernameValidator(validators.RegexValidator): ...
3+
class ASCIIUsernameValidator(RegexValidator): ...
4+
class UnicodeUsernameValidator(RegexValidator): ...

django-stubs/contrib/contenttypes/management/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Optional, Tuple, Type
1+
from typing import Any, Dict, List, Tuple, Type
22

33
from django.apps.config import AppConfig
44
from django.apps.registry import Apps

django-stubs/contrib/flatpages/admin.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any
22

3-
from django.contrib import admin as admin
3+
from django.contrib import admin
44

55
class FlatPageAdmin(admin.ModelAdmin):
66
form: Any = ...

django-stubs/contrib/gis/db/backends/oracle/models.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any
22

3-
from django.contrib.gis.db import models as models
4-
from django.contrib.gis.db.backends.base.models import SpatialRefSysMixin as SpatialRefSysMixin
3+
from django.contrib.gis.db import models
4+
from django.contrib.gis.db.backends.base.models import SpatialRefSysMixin
55

66
class OracleGeometryColumns(models.Model):
77
table_name: Any = ...

0 commit comments

Comments
 (0)