Skip to content

Commit

Permalink
remove some false positives, make parent Any
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov committed Mar 6, 2019
1 parent 95f1406 commit 47d9397
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion rest_framework-stubs/decorators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def action(
class MethodMapper(dict):
def __init__(self, action: Callable, methods: Sequence[str]) -> None: ...
def _map(self, method: str, func: Callable) -> Callable: ...
def get(self, func: Callable) -> Callable: ...
def get(self, func: Callable) -> Callable: ... # type: ignore
def post(self, func: Callable) -> Callable: ...
def put(self, func: Callable) -> Callable: ...
def patch(self, func: Callable) -> Callable: ...
Expand Down
3 changes: 2 additions & 1 deletion rest_framework-stubs/fields.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class Field(Generic[_FT, _FPT]):
default_validators: List[Callable] = ...
default_empty_html: Any = ...
initial: Optional[Any] = ...
parent: Optional[Field]
# TODO: add Generic/Plugin support for parent
parent: Optional[Any]
validators: Optional[List[_Validator]]
def __init__(
self,
Expand Down
2 changes: 1 addition & 1 deletion rest_framework-stubs/reverse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def _reverse(
**extra: Any
) -> str: ...

reverse_lazy: Callable[[...], str] = ...
reverse_lazy: Callable[..., str] = ...
3 changes: 1 addition & 2 deletions rest_framework-stubs/routers.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any, Callable, Dict, Iterable, List, Mapping, NamedTuple, Optional, Tuple, Type, Union

from django.utils import six
from django.utils.deprecation import RenameMethodsBase
from rest_framework.renderers import BaseRenderer
from rest_framework.request import Request
Expand Down Expand Up @@ -37,7 +36,7 @@ def flatten(list_of_lists: Iterable[Iterable[Any]]) -> Iterable[Any]: ...
class RenameRouterMethods(RenameMethodsBase):
renamed_methods: Iterable[Union[str, Callable]] = ...

class BaseRouter(six.with_metaclass(RenameRouterMethods)):
class BaseRouter(metaclass=RenameRouterMethods):
registry: List[Tuple[str, Type[ViewSetMixin], str]]
def register(
self, prefix: str, viewset: Type[ViewSetMixin], basename: Optional[str] = ..., base_name: Optional[str] = ...
Expand Down
2 changes: 1 addition & 1 deletion rest_framework-stubs/test.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ForceAuthClientHandler(ClientHandler):
def __init__(self, *args: Any, **kwargs: Any): ...
def get_response(self, request: HttpRequest) -> HttpResponse: ...

class APIClient(APIRequestFactory, DjangoClient):
class APIClient(APIRequestFactory, DjangoClient): # type: ignore
def credentials(self, **kwargs: Any): ...
def force_authenticate(self, user: Optional[Model] = ..., token: Optional[Any] = ...) -> None: ...

Expand Down
9 changes: 4 additions & 5 deletions rest_framework-stubs/viewsets.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections import OrderedDict
from typing import Any, Callable, List, Mapping, Optional
from typing import Any, Callable, List

from django.utils.decorators import classonlymethod
from rest_framework.request import Request

from rest_framework import generics, mixins, views
Expand All @@ -10,9 +9,9 @@ def _is_extra_action(attr: Any) -> bool: ...

class ViewSetMixin(object):
basename: str
request: Optional[Request]
@classonlymethod
def as_view(cls, actions: Optional[Mapping[str, str]] = ..., **initkwargs: Any) -> Callable: ...
request: Any
@classmethod
def as_view(cls, **initkwargs: Any) -> Callable: ...
def initialize_request(self, request: Request, *args: Any, **kwargs: Any) -> Request: ...
def reverse_action(self, url_name: str, *args: Any, **kwargs: Any) -> str: ...
@classmethod
Expand Down
10 changes: 10 additions & 0 deletions test-data/typecheck/all_imports.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[CASE test_to_import_all_modules_and_trigger_checking_of_stubs]
from rest_framework import (
apps, authentication, decorators, exceptions, fields, generics, metadata, mixins, negotiation,
pagination, parsers, permissions, relations, renderers, request, response, reverse, routers,
serializers, settings, status, test, throttling, validators, versioning, views, viewsets
)
from rest_framework.utils import (
encoders, field_mapping, json, serializer_helpers
)
[/CASE]

0 comments on commit 47d9397

Please sign in to comment.