From 981be4033fac5107bc0d1a0b0e75f2f5d9c6efc1 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 12 Aug 2019 19:32:52 +0300 Subject: [PATCH 1/2] Refactors bad default values, now using Ellipsis --- .editorconfig | 15 +++++++++++++++ django-stubs/contrib/postgres/search.pyi | 6 +++--- django-stubs/core/files/uploadhandler.pyi | 20 ++++++++++---------- django-stubs/db/models/query.pyi | 2 +- django-stubs/db/transaction.pyi | 2 +- django-stubs/http/response.pyi | 2 +- django-stubs/utils/datastructures.pyi | 2 +- django-stubs/views/generic/edit.pyi | 2 +- setup.cfg | 12 ++++++------ 9 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..7494e32dd --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# Check http://editorconfig.org for more information +# This is the main config file for this project: +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true + +[*.py] +indent_style = space +indent_size = 4 diff --git a/django-stubs/contrib/postgres/search.pyi b/django-stubs/contrib/postgres/search.pyi index 8e9955954..0223ed57c 100644 --- a/django-stubs/contrib/postgres/search.pyi +++ b/django-stubs/contrib/postgres/search.pyi @@ -13,7 +13,7 @@ class SearchVectorCombinable: ADD: str = ... class SearchVector(SearchVectorCombinable, Func): - config: Optional[Any] = None + config: Optional[Any] = ... def __init__(self, *expressions: Union[str, Combinable], **extra: Any): ... class CombinedSearchVector(SearchVectorCombinable, CombinedExpression): @@ -31,11 +31,11 @@ class SearchQueryCombinable: class SearchQuery(SearchQueryCombinable, Value): SEARCH_TYPES: Dict[str, str] = {"plain": "plainto_tsquery", "phrase": "phraseto_tsquery", "raw": "to_tsquery"} - def __init__(self, value, output_field=None, *, config=None, invert=False, search_type="plain"): ... + def __init__(self, value, output_field=..., *, config=..., invert=False, search_type="plain"): ... def __invert__(self: _T) -> _T: ... class CombinedSearchQuery(SearchQueryCombinable, CombinedExpression): - def __init__(self, lhs, connector, rhs, config, output_field=None) -> None: ... + def __init__(self, lhs, connector, rhs, config, output_field=...) -> None: ... class SearchRank(Func): def __init__(self, vector, query, **extra: Any) -> None: ... diff --git a/django-stubs/core/files/uploadhandler.pyi b/django-stubs/core/files/uploadhandler.pyi index bf79225c4..a8e8923cf 100644 --- a/django-stubs/core/files/uploadhandler.pyi +++ b/django-stubs/core/files/uploadhandler.pyi @@ -23,9 +23,9 @@ class FileUploadHandler: content_type_extra = ... # type: Optional[Dict[str, str]] request = ... # type: Optional[HttpRequest] field_name = ... # type: str - def __init__(self, request: HttpRequest = None) -> None: ... + def __init__(self, request: Optional[HttpRequest] = ...) -> None: ... def handle_raw_input( - self, input_data: IO[bytes], META: Dict[str, str], content_length: int, boundary: str, encoding: str = None + self, input_data: IO[bytes], META: Dict[str, str], content_length: int, boundary: str, encoding: Optional[str] = ... ) -> Optional[Tuple[QueryDict, MultiValueDict[str, UploadedFile]]]: ... def new_file( self, @@ -33,15 +33,15 @@ class FileUploadHandler: file_name: str, content_type: str, content_length: Optional[int], - charset: str = None, - content_type_extra: Dict[str, str] = None, + charset: Optional[str] = ..., + content_type_extra: Optional[Dict[str, str]] = ..., ) -> None: ... def receive_data_chunk(self, raw_data: bytes, start: int) -> Optional[bytes]: ... def file_complete(self, file_size: int) -> Optional[UploadedFile]: ... def upload_complete(self) -> None: ... class TemporaryFileUploadHandler(FileUploadHandler): - def __init__(self, request: HttpRequest = None) -> None: ... + def __init__(self, request: Optional[HttpRequest] = ...) -> None: ... file = ... # type: TemporaryUploadedFile def new_file( self, @@ -49,8 +49,8 @@ class TemporaryFileUploadHandler(FileUploadHandler): file_name: str, content_type: str, content_length: Optional[int], - charset: str = None, - content_type_extra: Dict[str, str] = None, + charset: Optional[str] = ..., + content_type_extra: Optional[Dict[str, str]] = ..., ) -> None: ... def receive_data_chunk(self, raw_data: bytes, start: int) -> Optional[bytes]: ... def file_complete(self, file_size: int) -> Optional[UploadedFile]: ... @@ -59,7 +59,7 @@ class MemoryFileUploadHandler(FileUploadHandler): activated = ... # type: bool file = ... # type: IO[bytes] def handle_raw_input( - self, input_data: IO[bytes], META: Dict[str, str], content_length: int, boundary: str, encoding: str = None + self, input_data: IO[bytes], META: Dict[str, str], content_length: int, boundary: str, encoding: Optional[str] = ... ) -> Optional[Tuple[QueryDict, MultiValueDict[str, UploadedFile]]]: ... def new_file( self, @@ -67,8 +67,8 @@ class MemoryFileUploadHandler(FileUploadHandler): file_name: str, content_type: str, content_length: Optional[int], - charset: str = None, - content_type_extra: Dict[str, str] = None, + charset: Optional[str] = ..., + content_type_extra: Optional[Dict[str, str]] = ..., ) -> None: ... def receive_data_chunk(self, raw_data: bytes, start: int) -> Optional[bytes]: ... def file_complete(self, file_size: int) -> Optional[UploadedFile]: ... diff --git a/django-stubs/db/models/query.pyi b/django-stubs/db/models/query.pyi index 53876843e..578fabae4 100644 --- a/django-stubs/db/models/query.pyi +++ b/django-stubs/db/models/query.pyi @@ -184,7 +184,7 @@ class RawQuerySet(Iterable[_T], Sized): def using(self, alias: Optional[str]) -> RawQuerySet[_T]: ... class Prefetch(object): - def __init__(self, lookup: str, queryset: Optional[QuerySet] = None, to_attr: Optional[str] = None) -> None: ... + def __init__(self, lookup: str, queryset: Optional[QuerySet] = ..., to_attr: Optional[str] = ...) -> None: ... def __getstate__(self) -> Dict[str, Any]: ... def add_prefix(self, prefix: str) -> None: ... def get_current_prefetch_to(self, level: int) -> str: ... diff --git a/django-stubs/db/transaction.pyi b/django-stubs/db/transaction.pyi index fa758b7d9..755c6d802 100644 --- a/django-stubs/db/transaction.pyi +++ b/django-stubs/db/transaction.pyi @@ -38,5 +38,5 @@ def atomic(using: _C) -> _C: ... # Decorator or context-manager with parameters @overload -def atomic(using: Optional[str] = None, savepoint: bool = True) -> Atomic: ... +def atomic(using: Optional[str] = ..., savepoint: bool = True) -> Atomic: ... def non_atomic_requests(using: Callable = ...) -> Callable: ... diff --git a/django-stubs/http/response.pyi b/django-stubs/http/response.pyi index 9d76ec0fc..edd26dcc0 100644 --- a/django-stubs/http/response.pyi +++ b/django-stubs/http/response.pyi @@ -49,7 +49,7 @@ class HttpResponseBase(Iterable[Any]): ) -> None: ... def setdefault(self, key: str, value: str) -> None: ... def set_signed_cookie(self, key: str, value: str, salt: str = "", **kwargs: Any) -> None: ... - def delete_cookie(self, key: str, path: str = "", domain: str = None) -> None: ... + def delete_cookie(self, key: str, path: str = "", domain: Optional[str] = ...) -> None: ... def make_bytes(self, value: object) -> bytes: ... def close(self) -> None: ... def write(self, content: Union[str, bytes]) -> None: ... diff --git a/django-stubs/utils/datastructures.pyi b/django-stubs/utils/datastructures.pyi index bf62139cf..738ee8881 100644 --- a/django-stubs/utils/datastructures.pyi +++ b/django-stubs/utils/datastructures.pyi @@ -39,7 +39,7 @@ class MultiValueDict(MutableMapping[_K, _V]): def __init__(self, key_to_list_mapping: Iterable[Tuple[_K, List[_V]]] = ...) -> None: ... def getlist(self, key: _K, default: Any = ...) -> List[_V]: ... def setlist(self, key: _K, list_: List[_V]) -> None: ... - def setlistdefault(self, key: _K, default_list: List[_V] = None) -> List[_V]: ... + def setlistdefault(self, key: _K, default_list: Optional[List[_V]] = ...) -> List[_V]: ... def appendlist(self, key: _K, value: _V) -> None: ... def lists(self) -> Iterable[Tuple[_K, List[_V]]]: ... def dict(self) -> Dict[_K, Union[_V, List[_V]]]: ... diff --git a/django-stubs/views/generic/edit.pyi b/django-stubs/views/generic/edit.pyi index d0672c6e4..a8c5e1542 100644 --- a/django-stubs/views/generic/edit.pyi +++ b/django-stubs/views/generic/edit.pyi @@ -17,7 +17,7 @@ class FormMixin(ContextMixin): def get_initial(self) -> Dict[str, Any]: ... def get_prefix(self) -> Optional[str]: ... def get_form_class(self) -> Type[BaseForm]: ... - def get_form(self, form_class: Optional[Type[BaseForm]] = None) -> BaseForm: ... + def get_form(self, form_class: Optional[Type[BaseForm]] = ...) -> BaseForm: ... def get_form_kwargs(self) -> Dict[str, Any]: ... def get_success_url(self) -> str: ... def form_valid(self, form: BaseForm) -> HttpResponse: ... diff --git a/setup.cfg b/setup.cfg index a8ecb8887..ea594bb7c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,17 +1,17 @@ [isort] skip = - django-sources, - django-stubs, - test-data + django-sources + django-stubs + test-data include_trailing_comma = true multi_line_output = 5 wrap_length = 120 [flake8] exclude = - django-sources, - django-stubs, - test-data + django-sources + django-stubs + test-data max_line_length = 120 [metadata] From ddfbf4fec852cca5da3beffc1fce994f869887b7 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 12 Aug 2019 19:41:23 +0300 Subject: [PATCH 2/2] Blacked --- django-stubs/core/files/uploadhandler.pyi | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/django-stubs/core/files/uploadhandler.pyi b/django-stubs/core/files/uploadhandler.pyi index a8e8923cf..79df95f64 100644 --- a/django-stubs/core/files/uploadhandler.pyi +++ b/django-stubs/core/files/uploadhandler.pyi @@ -25,7 +25,12 @@ class FileUploadHandler: field_name = ... # type: str def __init__(self, request: Optional[HttpRequest] = ...) -> None: ... def handle_raw_input( - self, input_data: IO[bytes], META: Dict[str, str], content_length: int, boundary: str, encoding: Optional[str] = ... + self, + input_data: IO[bytes], + META: Dict[str, str], + content_length: int, + boundary: str, + encoding: Optional[str] = ..., ) -> Optional[Tuple[QueryDict, MultiValueDict[str, UploadedFile]]]: ... def new_file( self, @@ -59,7 +64,12 @@ class MemoryFileUploadHandler(FileUploadHandler): activated = ... # type: bool file = ... # type: IO[bytes] def handle_raw_input( - self, input_data: IO[bytes], META: Dict[str, str], content_length: int, boundary: str, encoding: Optional[str] = ... + self, + input_data: IO[bytes], + META: Dict[str, str], + content_length: int, + boundary: str, + encoding: Optional[str] = ..., ) -> Optional[Tuple[QueryDict, MultiValueDict[str, UploadedFile]]]: ... def new_file( self,