Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI #1108

Merged
merged 30 commits into from
Aug 26, 2022
Merged

Fix CI #1108

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 0 additions & 78 deletions .github/workflows/release-django-stubs-ext.yml

This file was deleted.

76 changes: 0 additions & 76 deletions .github/workflows/release-django-stubs.yml

This file was deleted.

33 changes: 31 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,40 @@ jobs:
- name: Run pre-commit
run: pre-commit install && pre-commit run --all-files

mypy-self-check:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pip setuptools wheel
pip install -r ./requirements.txt

- name: Run mypy on plugin code
run: mypy --strict mypy_django_plugin

- name: Run mypy on ext code
run: mypy --strict django_stubs_ext
- name: Run mypy on scripts and utils
run: mypy --strict scripts
# TODO: run this check on versions, not only 3.10
- name: Run mypy on stubs
if: ${{ matrix.python-version }} == '3.10'
run: |
mypy --cache-dir=/dev/null --no-incremental django-stubs

test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8']
python-version: ['3.9']
steps:
- uses: actions/checkout@v3
- name: Setup system dependencies
Expand All @@ -46,7 +75,7 @@ jobs:
pip install -r ./requirements.txt

- name: Run tests
run: pytest --mypy-ini-file=mypy.ini
run: PYTHONPATH='.' pytest

typecheck:
runs-on: ubuntu-latest
Expand Down
24 changes: 3 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ repos:
rev: v2.37.3
hooks:
- id: pyupgrade
args: ["--py36-plus"]
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
args: ["--py37-plus"]
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black"]
- id: isort
name: isort (pyi)
types: [pyi]
args: ["--profile", "black"]
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
Expand All @@ -35,19 +33,3 @@ repos:
rev: 3.9.2
hooks:
- id: flake8
- repo: local
hooks:
- id: mypy
name: mypy
entry: mypy
language: system
types: [ python ]
exclude: "scripts/|django_stubs_ext/"
args: [ "--config=mypy.ini", "--cache-dir=/dev/null", "--no-incremental" ]
- id: mypy
name: mypy (django_stubs_ext)
entry: mypy
language: system
types: [ python ]
files: "django_stubs_ext/|django_stubs_ext/tests/"
args: [ "--config=mypy.ini", "--cache-dir=/dev/null", "--no-incremental", "--strict" ]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ This happens because these Django classes do not support [`__class_getitem__`](h

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

You can add extra types to patch with `django_stubs_ext.monkeypatch(extra_classes=[YourDesiredType])`

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.

### How can I create a HttpRequest that's guaranteed to have an authenticated user?
Expand Down
7 changes: 1 addition & 6 deletions django-stubs/contrib/admin/helpers.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from typing import Any, Callable, Dict, Iterable, Iterator, List, Mapping, Optional, Sequence, Tuple, Union

from django import forms
Expand All @@ -10,11 +9,7 @@ from django.forms.models import ModelForm
from django.forms.utils import ErrorDict, ErrorList
from django.forms.widgets import Media, Widget
from django.utils.safestring import SafeString

if sys.version_info < (3, 8):
from typing_extensions import TypedDict
else:
from typing import TypedDict
from typing_extensions import TypedDict

ACTION_CHECKBOX_NAME: str

Expand Down
7 changes: 1 addition & 6 deletions django-stubs/contrib/admin/options.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -43,11 +42,7 @@ from django.template.response import _TemplateForResponseT
from django.urls.resolvers import URLPattern
from django.utils.datastructures import _ListOrTuple
from django.utils.safestring import SafeString

if sys.version_info < (3, 8):
from typing_extensions import Literal, TypedDict
else:
from typing import Literal, TypedDict
from typing_extensions import Literal, TypedDict

IS_POPUP_VAR: str
TO_FIELD_VAR: str
Expand Down
7 changes: 1 addition & 6 deletions django-stubs/contrib/admin/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import datetime
import sys
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Set, Tuple, Type, Union, overload
from uuid import UUID

Expand All @@ -15,11 +14,7 @@ from django.forms.forms import BaseForm
from django.forms.formsets import BaseFormSet
from django.http.request import HttpRequest
from django.utils.datastructures import _IndexableCollection

if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal
from typing_extensions import Literal

class FieldIsAForeignKeyColumnName(Exception): ...

Expand Down
7 changes: 1 addition & 6 deletions django-stubs/contrib/admin/views/main.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Type, Union

from django.contrib.admin.filters import ListFilter
Expand All @@ -11,11 +10,7 @@ from django.db.models.options import Options
from django.db.models.query import QuerySet
from django.forms.formsets import BaseFormSet
from django.http.request import HttpRequest

if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal
from typing_extensions import Literal

ALL_VAR: str
ORDER_VAR: str
Expand Down
7 changes: 1 addition & 6 deletions django-stubs/contrib/auth/base_user.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import sys
from typing import Any, List, Optional, Tuple, TypeVar, Union, overload

from django.db import models
from django.db.models.base import Model
from django.db.models.expressions import Combinable
from django.db.models.fields import BooleanField

if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal
from typing_extensions import Literal

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

Expand Down
7 changes: 1 addition & 6 deletions django-stubs/contrib/auth/models.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from typing import Any, Iterable, Optional, Set, Tuple, Type, TypeVar, Union

from django.contrib.auth.base_user import AbstractBaseUser as AbstractBaseUser
Expand All @@ -8,11 +7,7 @@ from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models.base import Model
from django.db.models.manager import EmptyManager

if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal
from typing_extensions import Literal

_AnyUser = Union[Model, "AnonymousUser"]

Expand Down
6 changes: 3 additions & 3 deletions django-stubs/contrib/auth/validators.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.core import validators
from django.core.validators import RegexValidator

class ASCIIUsernameValidator(validators.RegexValidator): ...
class UnicodeUsernameValidator(validators.RegexValidator): ...
class ASCIIUsernameValidator(RegexValidator): ...
class UnicodeUsernameValidator(RegexValidator): ...
2 changes: 1 addition & 1 deletion django-stubs/contrib/contenttypes/management/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Tuple, Type
from typing import Any, Dict, List, Tuple, Type

from django.apps.config import AppConfig
from django.apps.registry import Apps
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/contrib/flatpages/admin.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any

from django.contrib import admin as admin
from django.contrib import admin

class FlatPageAdmin(admin.ModelAdmin):
form: Any = ...
Expand Down
4 changes: 2 additions & 2 deletions django-stubs/contrib/gis/db/backends/oracle/models.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any

from django.contrib.gis.db import models as models
from django.contrib.gis.db.backends.base.models import SpatialRefSysMixin as SpatialRefSysMixin
from django.contrib.gis.db import models
from django.contrib.gis.db.backends.base.models import SpatialRefSysMixin

class OracleGeometryColumns(models.Model):
table_name: Any = ...
Expand Down
Loading