diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-03-05 08:51:15 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-03-05 09:00:32 +0300 |
commit | 18c72bb588bd1bf332582b98058548f02e183e5d (patch) | |
tree | 21d752e5113b9d58276698044f3c53a6e3a636b5 /contrib/python/zope.interface/py3/zope/interface/interface.py | |
parent | 74819c4157bd388a7d429c870ea4b343a282dafa (diff) | |
download | ydb-18c72bb588bd1bf332582b98058548f02e183e5d.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib/python/zope.interface/py3/zope/interface/interface.py')
-rw-r--r-- | contrib/python/zope.interface/py3/zope/interface/interface.py | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/contrib/python/zope.interface/py3/zope/interface/interface.py b/contrib/python/zope.interface/py3/zope/interface/interface.py index 1bd6f9e818..8143daf3dd 100644 --- a/contrib/python/zope.interface/py3/zope/interface/interface.py +++ b/contrib/python/zope.interface/py3/zope/interface/interface.py @@ -15,14 +15,16 @@ """ # pylint:disable=protected-access import sys -from types import MethodType -from types import FunctionType import weakref +from types import FunctionType +from types import MethodType +from typing import Union +from zope.interface import ro from zope.interface._compat import _use_c_impl from zope.interface.exceptions import Invalid from zope.interface.ro import ro as calculate_ro -from zope.interface import ro + __all__ = [ # Most of the public API from this module is directly exported @@ -941,6 +943,14 @@ class InterfaceClass(_InterfaceClassBase): def __reduce__(self): return self.__name__ + def __or__(self, other): + """Allow type hinting syntax: Interface | None.""" + return Union[self, other] + + def __ror__(self, other): + """Allow type hinting syntax: None | Interface.""" + return Union[other, self] + Interface = InterfaceClass("Interface", __module__='zope.interface') # Interface is the only member of its own SRO. Interface._calculate_sro = lambda: (Interface,) @@ -1121,8 +1131,9 @@ def _wire(): # pylint:disable=wrong-import-position from zope.interface.declarations import implementedBy from zope.interface.declarations import providedBy -from zope.interface.exceptions import InvalidInterface from zope.interface.exceptions import BrokenImplementation +from zope.interface.exceptions import InvalidInterface + # This ensures that ``Interface`` winds up in the flattened() # list of the immutable declaration. It correctly overrides changed() |