Skip to content

Commit

Permalink
reformat with black
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov committed Dec 22, 2018
1 parent e407bf6 commit 32f2acc
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 108 deletions.
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
language: python
# cache package wheels (1 cache per python version)
cache: pip
# newer python versions are available only on xenial (while some older only on trusty) Ubuntu distribution
dist: xenial
sudo: required

jobs:
include:
- name: "run test suite with python 3.7"
python: 3.7
script: |
set -e
pytest
- name: "Lint with black"
python: 3.7
script: |
black --check --line-length=120 django-stubs/
before_install: |
# Upgrade pip, setuptools, and wheel
pip install -U pip setuptools wheel
install: |
pip install -r ./dev-requirements.txt
3 changes: 3 additions & 0 deletions reformat.xsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/local/bin/xonsh

black --line-length=120 rest_framework-stubs/
10 changes: 1 addition & 9 deletions rest_framework-stubs/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
from typing import Any, Union, Dict, Optional


class APIException(Exception):
status_code: int


class ValidationError(APIException):
detail: Union[str, Dict[str, Any]]

def __init__(self,
detail: Optional[Union[str, Dict[str, Any]]] = ...,
): ...

def __init__(self, detail: Optional[Union[str, Dict[str, Any]]] = ...): ...

class NotAuthenticated(APIException):
pass


class ParseError(APIException):
pass


class PermissionDenied(APIException):
pass
115 changes: 55 additions & 60 deletions rest_framework-stubs/fields.pyi
Original file line number Diff line number Diff line change
@@ -1,66 +1,61 @@
import datetime
from typing import Any, Union, Callable, Dict, NoReturn, Optional, List, TypeVar

_T = TypeVar('_T')
_T = TypeVar("_T")

class Field(object):
def __init__(self,
read_only: bool = ...,
write_only: bool = ...,
required: bool = ...,
default: Any = ...,
initial: Any = ...,
source: Union[Callable, str] = ...,
help_text: str = ...,
allow_null: bool = ...,
**kwargs): ...

def __init__(
self,
read_only: bool = ...,
write_only: bool = ...,
required: bool = ...,
default: Any = ...,
initial: Any = ...,
source: Union[Callable, str] = ...,
help_text: str = ...,
allow_null: bool = ...,
**kwargs
): ...
def bind(self, field_name: str, parent): ...

def to_representation(self, value: Any) -> Any: ...

def run_validation(self, data: Any = ...) -> Any: ...

def to_internal_value(self, data: Any): ...

def __get__(self, instance, owner) -> Any: ...

def fail(self, key: str, **kwargs) -> NoReturn: ...




class CharField(Field):
def __init__(self,
read_only: bool = ...,
write_only: bool = ...,
required: bool = ...,
default: Any = ...,
initial: Any = ...,
source: Union[Callable, str] = ...,
help_text: str = ...,
allow_null: bool = ...,
allow_blank: bool = ...,
trim_whitespace: bool = ...,
min_length: int = ...,
max_length: int = ...,
**kwargs): ...

def __init__(
self,
read_only: bool = ...,
write_only: bool = ...,
required: bool = ...,
default: Any = ...,
initial: Any = ...,
source: Union[Callable, str] = ...,
help_text: str = ...,
allow_null: bool = ...,
allow_blank: bool = ...,
trim_whitespace: bool = ...,
min_length: int = ...,
max_length: int = ...,
**kwargs
): ...
def __get__(self, instance, owner) -> str: ...

class RegexField(Field):
def __init__(self,
regex: str,
read_only: bool = ...,
write_only: bool = ...,
required: bool = ...,
default: Any = ...,
initial: Any = ...,
source: Union[Callable, str] = ...,
help_text: str = ...,
allow_null: bool = ...,
**kwargs): ...

def __init__(
self,
regex: str,
read_only: bool = ...,
write_only: bool = ...,
required: bool = ...,
default: Any = ...,
initial: Any = ...,
source: Union[Callable, str] = ...,
help_text: str = ...,
allow_null: bool = ...,
**kwargs
): ...
def __get__(self, instance, owner) -> str: ...

class EmailField(Field):
Expand All @@ -86,22 +81,22 @@ class ListField(Field):

class DictField(Field):
def __get__(self, instance, owner) -> Dict[str, Any]: ...

def run_child_validation(self, data: Dict[str, Any]) -> Dict[str, Any]: ...

class ChoiceField(Field):
def __init__(self,
choices: List[_T],
read_only: bool = ...,
write_only: bool = ...,
required: bool = ...,
default: Any = ...,
initial: Any = ...,
source: Union[Callable, str] = ...,
help_text: str = ...,
allow_null: bool = ...,
**kwargs): ...

def __init__(
self,
choices: List[_T],
read_only: bool = ...,
write_only: bool = ...,
required: bool = ...,
default: Any = ...,
initial: Any = ...,
source: Union[Callable, str] = ...,
help_text: str = ...,
allow_null: bool = ...,
**kwargs
): ...
def __get__(self, instance, owner) -> _T: ...

class JSONField(Field):
Expand Down
51 changes: 26 additions & 25 deletions rest_framework-stubs/serializers.pyi
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
from typing import Dict

from rest_framework.fields import (Field as Field,
CharField as CharField,
RegexField as RegexField,
EmailField as EmailField,
URLField as URLField,
FileField as FileField,
IntegerField as IntegerField,
FloatField as FloatField,
BooleanField as BooleanField,
NullBooleanField as NullBooleanField,
ListField as ListField,
DictField as DictField,
ChoiceField as ChoiceField,
JSONField as JSONField,
DateTimeField as DateTimeField,
SerializerMethodField as SerializerMethodField)
from rest_framework.exceptions import (APIException as APIException,
ValidationError as ValidationError,
ParseError as ParseError,
NotAuthenticated as NotAuthenticated,
PermissionDenied as PermissionDenied)

from rest_framework.fields import (
Field as Field,
CharField as CharField,
RegexField as RegexField,
EmailField as EmailField,
URLField as URLField,
FileField as FileField,
IntegerField as IntegerField,
FloatField as FloatField,
BooleanField as BooleanField,
NullBooleanField as NullBooleanField,
ListField as ListField,
DictField as DictField,
ChoiceField as ChoiceField,
JSONField as JSONField,
DateTimeField as DateTimeField,
SerializerMethodField as SerializerMethodField,
)
from rest_framework.exceptions import (
APIException as APIException,
ValidationError as ValidationError,
ParseError as ParseError,
NotAuthenticated as NotAuthenticated,
PermissionDenied as PermissionDenied,
)

class BaseSerializer(Field):
pass


class Serializer(BaseSerializer):
@property
def fields(self) -> Dict[str, Field]: ...

def get_fields(self) -> Dict[str, Field]: ...
def get_fields(self) -> Dict[str, Field]: ...
5 changes: 1 addition & 4 deletions rest_framework-stubs/status.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ See RFC 2616 - https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
And RFC 6585 - https://tools.ietf.org/html/rfc6585
And RFC 4918 - https://tools.ietf.org/html/rfc4918
"""
def is_informational(code: int) -> bool: ...

def is_informational(code: int) -> bool: ...
def is_success(code: int) -> bool: ...

def is_redirect(code: int) -> bool: ...

def is_client_error(code: int) -> bool: ...

def is_server_error(code: int) -> bool: ...

HTTP_100_CONTINUE = 100
Expand Down
2 changes: 1 addition & 1 deletion rest_framework-stubs/validators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ class UniqueValidator(object):
pass

class UniqueTogetherValidator(object):
pass
pass
9 changes: 0 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
from distutils.core import setup


def find_stubs(package):
stubs = []
for fpath in os.scandir(package):
if fpath.is_file():
path = fpath.path.replace(package + os.sep, 'rest_framework' + os.sep, 1)
stubs.append(path)
return {package: stubs}


setup(
name="djangorestframework-stubs",
url="https://github.com/mkurnikov/djangorestframework-stubs.git",
Expand Down

0 comments on commit 32f2acc

Please sign in to comment.