Skip to content

Commit fde071b

Browse files
committed
fix classonlymethod, replace with six from typeshed
1 parent 324b961 commit fde071b

File tree

2 files changed

+95
-141
lines changed

2 files changed

+95
-141
lines changed

django-stubs/utils/decorators.pyi

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
from typing import Any, Callable, Optional, Set, Tuple, Type, Union
22

3-
from django.contrib.auth.mixins import AccessMixin
4-
from django.contrib.messages.views import SuccessMessageMixin
53
from django.middleware.cache import CacheMiddleware
64
from django.test.testcases import LiveServerTestCase
75
from django.utils.deprecation import MiddlewareMixin
8-
from django.views.generic.base import TemplateResponseMixin, View
96

10-
class classonlymethod(classmethod):
11-
def __get__(
12-
self,
13-
instance: Optional[View],
14-
cls: Type[Union[AccessMixin, SuccessMessageMixin, TemplateResponseMixin, View]] = ...,
15-
) -> Callable: ...
7+
class classonlymethod(classmethod): ...
168

179
def method_decorator(
1810
decorator: Union[Callable, Set[Callable], Tuple[Callable, Callable]], name: str = ...

django-stubs/utils/six.pyi

Lines changed: 94 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,106 @@
1+
from __future__ import print_function
2+
13
import types
2-
from typing import Any, Optional
3-
4-
PY2: Any
5-
PY3: Any
6-
PY34: Any
7-
string_types: Any
8-
integer_types: Any
9-
class_types: Any
4+
import typing
5+
import unittest
6+
from typing import (
7+
Any,
8+
AnyStr,
9+
Callable,
10+
Dict,
11+
ItemsView,
12+
Iterable,
13+
KeysView,
14+
Mapping,
15+
NoReturn,
16+
Optional,
17+
Pattern,
18+
Text,
19+
Tuple,
20+
Type,
21+
TypeVar,
22+
Union,
23+
ValuesView,
24+
overload,
25+
)
26+
27+
# Exports
28+
29+
_T = TypeVar("_T")
30+
_K = TypeVar("_K")
31+
_V = TypeVar("_V")
32+
33+
# TODO make constant, then move this stub to 2and3
34+
# https://github.com/python/typeshed/issues/17
35+
PY2 = False
36+
PY3 = True
37+
PY34 = ... # type: bool
38+
39+
string_types = (str,)
40+
integer_types = (int,)
41+
class_types = (type,)
1042
text_type = str
1143
binary_type = bytes
12-
MAXSIZE: Any
13-
text_type = unicode
14-
binary_type = str
15-
16-
class X:
17-
def __len__(self): ...
18-
19-
class _LazyDescr:
20-
name: Any = ...
21-
def __init__(self, name: Any) -> None: ...
22-
def __get__(self, obj: Any, tp: Any): ...
23-
24-
class MovedModule(_LazyDescr):
25-
mod: Any = ...
26-
def __init__(self, name: Any, old: Any, new: Optional[Any] = ...) -> None: ...
27-
def __getattr__(self, attr: Any): ...
28-
29-
class _LazyModule(types.ModuleType):
30-
__doc__: Any = ...
31-
def __init__(self, name: Any) -> None: ...
32-
def __dir__(self): ...
33-
34-
class MovedAttribute(_LazyDescr):
35-
mod: Any = ...
36-
attr: Any = ...
37-
def __init__(
38-
self, name: Any, old_mod: Any, new_mod: Any, old_attr: Optional[Any] = ..., new_attr: Optional[Any] = ...
39-
) -> None: ...
40-
41-
class _SixMetaPathImporter:
42-
name: Any = ...
43-
known_modules: Any = ...
44-
def __init__(self, six_module_name: Any) -> None: ...
45-
def find_module(self, fullname: Any, path: Optional[Any] = ...): ...
46-
def load_module(self, fullname: Any): ...
47-
def is_package(self, fullname: Any): ...
48-
def get_code(self, fullname: Any): ...
49-
get_source: Any = ...
50-
51-
class _MovedItems(_LazyModule):
52-
__path__: Any = ...
53-
54-
moves: Any
55-
56-
class Module_six_moves_urllib_parse(_LazyModule): ...
57-
class Module_six_moves_urllib_error(_LazyModule): ...
58-
class Module_six_moves_urllib_request(_LazyModule): ...
59-
class Module_six_moves_urllib_response(_LazyModule): ...
60-
class Module_six_moves_urllib_robotparser(_LazyModule): ...
61-
62-
class Module_six_moves_urllib(types.ModuleType):
63-
__path__: Any = ...
64-
parse: Any = ...
65-
error: Any = ...
66-
request: Any = ...
67-
response: Any = ...
68-
robotparser: Any = ...
69-
def __dir__(self): ...
70-
71-
def add_move(move: Any) -> None: ...
72-
def remove_move(name: Any) -> None: ...
73-
74-
advance_iterator = next
75-
next = advance_iterator
76-
callable = callable
77-
78-
def get_unbound_function(unbound: Any): ...
79-
80-
create_bound_method: Any
81-
82-
def create_unbound_method(func: Any, cls: Any): ...
83-
84-
Iterator = object
8544

86-
class Iterator:
87-
def next(self): ...
45+
MAXSIZE = ... # type: int
8846

89-
callable = callable
90-
get_method_function: Any
91-
get_method_self: Any
92-
get_function_closure: Any
93-
get_function_code: Any
94-
get_function_defaults: Any
95-
get_function_globals: Any
47+
# def add_move
48+
# def remove_move
9649

97-
def iterkeys(d: Any, **kw: Any): ...
98-
def itervalues(d: Any, **kw: Any): ...
99-
def iteritems(d: Any, **kw: Any): ...
100-
def iterlists(d: Any, **kw: Any): ...
50+
def callable(obj: object) -> bool: ...
51+
def get_unbound_function(unbound: types.FunctionType) -> types.FunctionType: ...
52+
def create_bound_method(func: types.FunctionType, obj: object) -> types.MethodType: ...
53+
def create_unbound_method(func: types.FunctionType, cls: type) -> types.FunctionType: ...
10154

102-
viewkeys: Any
103-
viewvalues: Any
104-
viewitems: Any
105-
106-
def b(s: Any): ...
107-
def u(s: Any): ...
108-
109-
unichr = chr
110-
int2byte: Any
111-
byte2int: Any
112-
indexbytes: Any
113-
iterbytes = iter
114-
StringIO: Any
115-
BytesIO: Any
116-
unichr = unichr
117-
int2byte = chr
118-
119-
def assertCountEqual(self, *args: Any, **kwargs: Any): ...
120-
def assertRaisesRegex(self, *args: Any, **kwargs: Any): ...
121-
def assertRegex(self, *args: Any, **kwargs: Any): ...
122-
123-
exec_: Any
124-
125-
def reraise(tp: Any, value: Any, tb: Optional[Any] = ...) -> None: ...
126-
def raise_from(value: Any, from_value: Any) -> None: ...
55+
Iterator = object
12756

128-
print_: Any
129-
_print = print_
57+
def get_method_function(meth: types.MethodType) -> types.FunctionType: ...
58+
def get_method_self(meth: types.MethodType) -> Optional[object]: ...
59+
def get_function_closure(fun: types.FunctionType) -> Optional[Tuple[types._Cell, ...]]: ...
60+
def get_function_code(fun: types.FunctionType) -> types.CodeType: ...
61+
def get_function_defaults(fun: types.FunctionType) -> Optional[Tuple[Any, ...]]: ...
62+
def get_function_globals(fun: types.FunctionType) -> Dict[str, Any]: ...
63+
def iterkeys(d: Mapping[_K, _V]) -> typing.Iterator[_K]: ...
64+
def itervalues(d: Mapping[_K, _V]) -> typing.Iterator[_V]: ...
65+
def iteritems(d: Mapping[_K, _V]) -> typing.Iterator[Tuple[_K, _V]]: ...
13066

131-
def wraps(wrapped: Any, assigned: Any = ..., updated: Any = ...): ...
67+
# def iterlists
13268

133-
wraps: Any
69+
def viewkeys(d: Mapping[_K, _V]) -> KeysView[_K]: ...
70+
def viewvalues(d: Mapping[_K, _V]) -> ValuesView[_V]: ...
71+
def viewitems(d: Mapping[_K, _V]) -> ItemsView[_K, _V]: ...
72+
def b(s: str) -> binary_type: ...
73+
def u(s: str) -> text_type: ...
13474

135-
def with_metaclass(meta: Any, *bases: Any): ...
136-
def add_metaclass(metaclass: Any): ...
137-
def python_2_unicode_compatible(klass: Any): ...
75+
unichr = chr
13876

139-
__path__: Any
140-
__package__ = __name__
141-
memoryview = memoryview
142-
buffer_types: Any
143-
memoryview = memoryview
144-
memoryview = buffer
77+
def int2byte(i: int) -> bytes: ...
78+
def byte2int(bs: binary_type) -> int: ...
79+
def indexbytes(buf: binary_type, i: int) -> int: ...
80+
def iterbytes(buf: binary_type) -> typing.Iterator[int]: ...
81+
def assertCountEqual(
82+
self: unittest.TestCase, first: Iterable[_T], second: Iterable[_T], msg: Optional[str] = ...
83+
) -> None: ...
84+
@overload
85+
def assertRaisesRegex(self: unittest.TestCase, msg: Optional[str] = ...) -> Any: ...
86+
@overload
87+
def assertRaisesRegex(self: unittest.TestCase, callable_obj: Callable[..., Any], *args: Any, **kwargs: Any) -> Any: ...
88+
def assertRegex(
89+
self: unittest.TestCase, text: AnyStr, expected_regex: Union[AnyStr, Pattern[AnyStr]], msg: Optional[str] = ...
90+
) -> None: ...
91+
92+
exec_ = exec
93+
94+
def reraise(
95+
tp: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType] = ...
96+
) -> NoReturn: ...
97+
def raise_from(value: Union[BaseException, Type[BaseException]], from_value: Optional[BaseException]) -> NoReturn: ...
98+
99+
print_ = print
100+
101+
def with_metaclass(meta: type, *bases: type) -> type: ...
102+
def add_metaclass(metaclass: type) -> Callable[[_T], _T]: ...
103+
def ensure_binary(s: Union[bytes, Text], encoding: str = ..., errors: str = ...) -> bytes: ...
104+
def ensure_str(s: Union[bytes, Text], encoding: str = ..., errors: str = ...) -> str: ...
105+
def ensure_text(s: Union[bytes, Text], encoding: str = ..., errors: str = ...) -> Text: ...
106+
def python_2_unicode_compatible(klass: _T) -> _T: ...

0 commit comments

Comments
 (0)