Skip to content

Commit 503eaaa

Browse files
Setup mypy (#73)
* Setup mypy * Add py.typed
1 parent 6b45fb8 commit 503eaaa

File tree

13 files changed

+23
-16
lines changed

13 files changed

+23
-16
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
include:
1515
- name: Check
1616
python: "3.6"
17-
install: pip install -U black
17+
install: pip install -U black mypy
1818
script: scripts/check
1919

2020
install:

mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mypy]
2+
files = rest_framework_api_key
3+
ignore_missing_imports = True

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ readme = "README.md"
99
repository = "https://github.com/florimondmanca/djangorestframework-api-key"
1010
homepage = "https://florimondmanca.github.io/djangorestframework-api-key/"
1111
documentation = "https://florimondmanca.github.io/djangorestframework-api-key/"
12+
packages = [
13+
{ include = "rest_framework_api_key" }
14+
]
15+
include = ["rest_framework_api_key/py.typed"]
1216
license = "MIT"
1317
classifiers=[
1418
"Development Status :: 4 - Beta",

rest_framework_api_key/admin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ class APIKeyModelAdmin(admin.ModelAdmin):
1717
list_filter = ("created",)
1818
search_fields = ("name", "prefix")
1919

20-
def get_readonly_fields(self, request, obj: APIKey = None) -> typing.Tuple[str]:
21-
fields = ("prefix",)
20+
def get_readonly_fields(
21+
self, request, obj: APIKey = None
22+
) -> typing.Tuple[str, ...]:
23+
fields = ("prefix",) # type: typing.Tuple[str, ...]
2224
if obj is not None and obj.revoked:
2325
fields = fields + ("name", "revoked", "expiry_date")
2426
return fields

rest_framework_api_key/migrations/0001_initial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Migration(migrations.Migration):
77

88
initial = True
99

10-
dependencies = []
10+
dependencies = [] # type: ignore
1111

1212
operations = [
1313
migrations.CreateModel(

rest_framework_api_key/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def assign_key(self, obj: "AbstractAPIKey") -> str:
1414
try:
1515
key, prefix, hashed_key = self.key_generator.generate()
1616
except ValueError: # Compatibility with < 1.4
17-
key, hashed_key = self.key_generator.generate()
17+
key, hashed_key = self.key_generator.generate() # type: ignore
1818
pk = hashed_key
1919
prefix, hashed_key = split(hashed_key)
2020
else:
@@ -108,8 +108,8 @@ def _has_expired(self) -> bool:
108108
return False
109109
return self.expiry_date < timezone.now()
110110

111-
_has_expired.short_description = "Has expired"
112-
_has_expired.boolean = True
111+
_has_expired.short_description = "Has expired" # type: ignore
112+
_has_expired.boolean = True # type: ignore
113113
has_expired = property(_has_expired)
114114

115115
def is_valid(self, key: str) -> bool:

rest_framework_api_key/permissions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
from .models import AbstractAPIKey, APIKey
88

9+
if typing.TYPE_CHECKING:
10+
from django.db import models
11+
912

1013
class KeyParser:
1114
def get(self, request: HttpRequest) -> typing.Optional[str]:
@@ -34,7 +37,7 @@ def get_from_header(self, request: HttpRequest, name: str) -> typing.Optional[st
3437

3538

3639
class BaseHasAPIKey(permissions.BasePermission):
37-
model = None
40+
model = None # type: typing.Type[models.Model]
3841
key_parser = KeyParser()
3942

4043
def get_key(self, request: HttpRequest) -> typing.Optional[str]:

rest_framework_api_key/py.typed

Whitespace-only changes.

scripts/check

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#!/bin/sh -e
2-
set -x
3-
42
black --check --target-version=py35 rest_framework_api_key tests
3+
mypy

scripts/lint

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
#!/bin/sh -e
2-
set -x
3-
42
black --target-version=py35 rest_framework_api_key tests

0 commit comments

Comments
 (0)