File: overloads_demo.py

package info (click to toggle)
sphinx-toolbox 3.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,924 kB
  • sloc: python: 11,636; sh: 26; javascript: 25; makefile: 16
file content (81 lines) | stat: -rw-r--r-- 1,913 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# stdlib
from typing import Callable, List, Optional, Type, Union, overload

__all__ = ("serde", "Foo", "Bar")


@overload
def serde(cls: Type[object], from_key: str = ..., to_key: str = ...) -> Type[object]: ...  # pragma: no cover


@overload
def serde(cls: None = None, from_key: str = ..., to_key: str = ...) -> "Callable[[Type[object]], Type[object]]": ...  # pragma: no cover


def serde(  # type: ignore[empty-body]
		cls: Optional[Type[object]] = None,
		from_key: str = "from",
		to_key: str = "to",
		) -> Union[Type[object], Callable[[Type[object]], Type[object]]]:
	r"""
	Decorator to add serialisation and deserialisation capabilities to attrs classes.

	:param cls: The attrs class to add the methods to.
	:param from_key:
	:param to_key:

	:rtype:

	Classes decorated with :deco:`~attr_utils.serialise.serde` will have two new methods added:

	.. py:classmethod:: from_dict(d)

		Construct an instance of the class from a dictionary.

		:param d: :class:`~typing.Mapping`\[:class:`str`, :py:obj:`~typing.Any`\]

	.. py:method:: to_dict() -> MutableMapping[str, Any]:

		Returns a dictionary containing the contents of the class.

		:rtype: :class:`~typing.MutableMapping`\[:class:`str`, :py:obj:`~typing.Any`\]

	"""


class Foo:

	@overload
	def __getitem__(self, item: int) -> str: ...

	@overload
	def __getitem__(self, item: slice) -> List[str]: ...

	def __getitem__(self, item: Union[int, slice]) -> Union[str, List[str]]:  # type: ignore[empty-body]
		"""
		Return the item with the given index.

		:param item:

		:rtype:

		.. versionadded:: 1.2.3
		"""


class Bar:

	@overload
	def __getitem__(self, item: int) -> str: ...

	@overload
	def __getitem__(self, item: slice) -> List[str]: ...

	def __getitem__(self, item: Union[int, slice]) -> Union[str, List[str]]:  # type: ignore[empty-body]
		"""
		Return the item with the given index.

		.. versionadded:: 1.2.3

		:param item:
		"""