File: autoprotocol_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 (48 lines) | stat: -rw-r--r-- 981 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
# stdlib
from abc import abstractmethod
from typing import Any, TypeVar

# 3rd party
from domdf_python_tools.doctools import prettify_docstrings
from typing_extensions import Protocol, runtime_checkable

__all__ = ("HasLessThan", "HasGreaterThan", "Frobnicater")


@prettify_docstrings
class HasLessThan(Protocol):
	"""
	:class:`typing.Protocol` for classes that support the ``<`` operator.
	"""

	def __lt__(self, other) -> bool: ...


@prettify_docstrings
class HasGreaterThan(Protocol):

	def __gt__(self, other) -> bool: ...


@runtime_checkable
class Frobnicater(Protocol):

	def frobnicate(self, something) -> Any: ...


# From https://github.com/python/cpython/blob/main/Lib/typing.py

T_co = TypeVar("T_co", covariant=True)  # Any type covariant containers.


@runtime_checkable
class SupportsAbs(Protocol[T_co]):
	"""
	An ABC with one abstract method __abs__ that is covariant in its return type.
	"""

	__slots__ = ()

	@abstractmethod
	def __abs__(self) -> T_co:
		pass