|
6 | 6 | from __future__ import unicode_literals |
7 | 7 |
|
8 | 8 | import typing |
| 9 | +from typing import cast |
9 | 10 | from copy import deepcopy |
10 | 11 |
|
11 | 12 | import six |
|
15 | 16 | from .errors import MissingInfoNamespace |
16 | 17 | from .permissions import Permissions |
17 | 18 | from .time import epoch_to_datetime |
18 | | -from ._typing import overload |
| 19 | +from ._typing import overload, Text |
19 | 20 |
|
20 | 21 | if False: # typing.TYPE_CHECKING |
21 | 22 | from datetime import datetime |
22 | | - from typing import Callable, List, Mapping, Optional |
23 | | - from ._typing import Text |
| 23 | + from typing import Any, Callable, List, Mapping, Optional, Union |
24 | 24 | RawInfo = Mapping[Text, Mapping[Text, object]] |
25 | 25 | ToDatetime = Callable[[int], datetime] |
26 | 26 | T = typing.TypeVar("T") |
@@ -82,23 +82,18 @@ def _make_datetime(self, t): |
82 | 82 | else: |
83 | 83 | return None |
84 | 84 |
|
85 | | - @overload |
86 | | - def get(self, namespace, key, default=None): # pragma: no cover |
87 | | - # type: (Text, Text, Optional[T]) -> Optional[T] |
88 | | - pass |
89 | | - |
90 | 85 | @overload |
91 | 86 | def get(self, namespace, key): # pragma: no cover |
92 | | - # type: (Text, Text) -> Optional[T] |
| 87 | + # type: (Text, Text) -> Any |
93 | 88 | pass |
94 | 89 |
|
95 | 90 | @overload |
96 | 91 | def get(self, namespace, key, default): # pragma: no cover |
97 | | - # type: (Text, Text, T) -> T |
| 92 | + # type: (Text, Text, T) -> Union[Any, T] |
98 | 93 | pass |
99 | 94 |
|
100 | 95 | def get(self, namespace, key, default=None): |
101 | | - # type: (Text, Text, Optional[T]) -> Optional[T] |
| 96 | + # type: (Text, Text, Optional[Any]) -> Optional[Any] |
102 | 97 | """Get a raw info value. |
103 | 98 |
|
104 | 99 | Arguments: |
@@ -187,7 +182,7 @@ def name(self): |
187 | 182 | # type: () -> Text |
188 | 183 | """`str`: the resource name. |
189 | 184 | """ |
190 | | - return self.get('basic', 'name') |
| 185 | + return cast(Text, self.get('basic', 'name')) |
191 | 186 |
|
192 | 187 | @property |
193 | 188 | def suffix(self): |
@@ -245,14 +240,14 @@ def is_dir(self): |
245 | 240 | # type: () -> bool |
246 | 241 | """`bool`: `True` if the resource references a directory. |
247 | 242 | """ |
248 | | - return self.get('basic', 'is_dir') |
| 243 | + return cast(bool, self.get('basic', 'is_dir')) |
249 | 244 |
|
250 | 245 | @property |
251 | 246 | def is_file(self): |
252 | 247 | # type: () -> bool |
253 | 248 | """`bool`: `True` if the resource references a file. |
254 | 249 | """ |
255 | | - return not self.get('basic', 'is_dir') |
| 250 | + return not cast(bool, self.get('basic', 'is_dir')) |
256 | 251 |
|
257 | 252 | @property |
258 | 253 | def is_link(self): |
@@ -381,7 +376,7 @@ def size(self): |
381 | 376 |
|
382 | 377 | """ |
383 | 378 | self._require_namespace('details') |
384 | | - return self.get('details', 'size') |
| 379 | + return cast(int, self.get('details', 'size')) |
385 | 380 |
|
386 | 381 | @property |
387 | 382 | def user(self): |
|
0 commit comments