Skip to content

Commit

Permalink
Update type hints (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
florimondmanca authored Apr 6, 2020
1 parent 9ba3790 commit 7ed909a
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 20 deletions.
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ django[argon2,bcrypt]==3.0.*
djangorestframework==3.10.*
dj-database-url
django-dotenv
django-stubs
djangorestframework-stubs

# PostgreSQL testing.
psycopg2-binary
Expand Down
8 changes: 3 additions & 5 deletions scripts/check
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

. scripts/env

export TYPED_SOURCE_FILES="src/rest_framework_api_key tests/conftest.py"
export SOURCE_FILES="$TYPED_SOURCE_FILES test_project/"
export SOURCE_FILES="src/rest_framework_api_key test_project/ tests/conftest.py"

set -x

${PREFIX}black --check --diff --target-version=py36 $SOURCE_FILES
${PREFIX}flake8 $SOURCE_FILES
${PREFIX}mypy $TYPED_SOURCE_FILES
${PREFIX}mypy $SOURCE_FILES
${PREFIX}isort --check --diff --project=djangorestframework-api-key --recursive $SOURCE_FILES

scripts/makemigrations --check
${PREFIX}python scripts/makemigrations --check
4 changes: 0 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ max-line-length = 88
[mypy]
disallow_untyped_defs = True
ignore_missing_imports = True
plugins = mypy_django_plugin.main, mypy_drf_plugin.main

[mypy.plugins.django-stubs]
django_settings_module = test_project.project.settings

[tool:isort]
combine_as_imports = True
Expand Down
1 change: 1 addition & 0 deletions src/rest_framework_api_key/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class APIKeyModelAdmin(admin.ModelAdmin):
model: typing.Type[AbstractAPIKey]

list_display = (
"prefix",
"name",
Expand Down
2 changes: 2 additions & 0 deletions src/rest_framework_api_key/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Migration(migrations.Migration):

initial = True

dependencies = [] # type: ignore

operations = [
migrations.CreateModel(
name="APIKey",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# Generated by Django 2.2.2 on 2019-06-29 10:38

from django.apps.registry import Apps
from django.db import migrations, models
from django.db.backends.base.schema import BaseDatabaseSchemaEditor

APP_NAME = "rest_framework_api_key"
MODEL_NAME = "apikey"
DEPENDENCIES = [(APP_NAME, "0003_auto_20190623_1952")]


def populate_prefix_hashed_key(
apps: Apps, schema_editor: BaseDatabaseSchemaEditor
) -> None:
def populate_prefix_hashed_key(apps, schema_editor) -> None: # type: ignore
model = apps.get_model(APP_NAME, MODEL_NAME)

for api_key in model.objects.all():
Expand Down
2 changes: 1 addition & 1 deletion src/rest_framework_api_key/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_from_header(self, request: HttpRequest, name: str) -> typing.Optional[st


class BaseHasAPIKey(permissions.BasePermission):
model: typing.Optional[typing.Type[APIKey]] = None
model: typing.Optional[typing.Type[AbstractAPIKey]] = None
key_parser = KeyParser()

def get_key(self, request: HttpRequest) -> typing.Optional[str]:
Expand Down
2 changes: 1 addition & 1 deletion test_project/heroes/migrations/0002_prefix_hashed_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
DEPENDENCIES = [(APP_NAME, "0001_initial")]


def populate_prefix_hashed_key(apps, schema_editor):
def populate_prefix_hashed_key(apps, schema_editor): # type: ignore
model = apps.get_model(APP_NAME, MODEL_NAME)

for api_key in model.objects.all():
Expand Down
4 changes: 2 additions & 2 deletions test_project/heroes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class Hero(models.Model):
class Meta:
verbose_name_plural = "heroes"

def __str__(self):
def __str__(self) -> str:
return self.name


class HeroAPIKeyManager(BaseAPIKeyManager):
def get_usable_keys(self):
def get_usable_keys(self) -> models.QuerySet:
return super().get_usable_keys().filter(hero__retired=False)


Expand Down

0 comments on commit 7ed909a

Please sign in to comment.