�
JDvc�( � � � d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z g Z
G d� d e� � Z G d
� de� � Z
d� Z e� � ZdS )
� N)�FunctionType)�classImplements)� Interface)�fromFunction)�InterfaceClass)�_decorator_non_returnc � � e Zd Zd� ZdS )�optionalc � � |j | _ d S �N��__doc__)�self�methods �@/usr/lib/python3/dist-packages/zope/interface/common/__init__.py�__init__zoptional.__init__# s � ��~����� N)�__name__�
__module__�__qualname__r � r r r
r
s# � � � � � �&� &� &� &� &r r
c �z � e Zd ZdZd� Zed� � � Zd� Zed� � � Zed� � � Z d� Z
dd �Zd
� Zd� Z
dS )
�ABCInterfaceClassa�
An interface that is automatically derived from a
:class:`abc.ABCMeta` type.
Internal use only.
The body of the interface definition *must* define
a property ``abc`` that is the ABC to base the interface on.
If ``abc`` is *not* in the interface definition, a regular
interface will be defined instead (but ``extra_classes`` is still
respected).
Use the ``@optional`` decorator on method definitions if
the ABC defines methods that are not actually required in all cases
because the Python language has multiple ways to implement a protocol.
For example, the ``iter()`` protocol can be implemented with
``__iter__`` or the pair ``__len__`` and ``__getitem__``.
When created, any existing classes that are registered to conform
to the ABC are declared to implement this interface. This is *not*
automatically updated as the ABC registry changes. If the body of the
interface definition defines ``extra_classes``, it should be a
tuple giving additional classes to declare implement the interface.
Note that this is not fully symmetric. For example, it is usually
the case that a subclass relationship carries the interface
declarations over::
>>> from zope.interface import Interface
>>> class I1(Interface):
... pass
...
>>> from zope.interface import implementer
>>> @implementer(I1)
... class Root(object):
... pass
...
>>> class Child(Root):
... pass
...
>>> child = Child()
>>> isinstance(child, Root)
True
>>> from zope.interface import providedBy
>>> list(providedBy(child))
[<InterfaceClass __main__.I1>]
However, that's not the case with ABCs and ABC interfaces. Just
because ``isinstance(A(), AnABC)`` and ``isinstance(B(), AnABC)``
are both true, that doesn't mean there's any class hierarchy
relationship between ``A`` and ``B``, or between either of them
and ``AnABC``. Thus, if ``AnABC`` implemented ``IAnABC``, it would
not follow that either ``A`` or ``B`` implements ``IAnABC`` (nor
their instances provide it)::
>>> class SizedClass(object):
... def __len__(self): return 1
...
>>> from collections.abc import Sized
>>> isinstance(SizedClass(), Sized)
True
>>> from zope.interface import classImplements
>>> classImplements(Sized, I1)
None
>>> list(providedBy(SizedClass()))
[]
Thus, to avoid conflicting assumptions, ABCs should not be
declared to implement their parallel ABC interface. Only concrete
classes specifically registered with the ABC should be declared to
do so.
.. versionadded:: 5.0.0
c �� � � |� _ |� dd� � }|� dd� � }d|vrAt j � |||� � t � � ||� � t � _ d S |� d� � }|� _ t |� � � _ t |� � � _
|dd � |j k sJ ||f� � �� fd�t |� � � � � D � � }� �
|� � |d< |