3
8ßL]-  ã               @   sn   d Z ddlmZ ddlZddlmZmZmZmZm	Z	m
Z
mZmZ G dd„ deƒZejeƒG dd	„ d	eƒƒZdS )
aÿ   Adds a "category" capability to Traits-based classes, similar to that
    provided by the Cocoa (Objective-C) environment for the Macintosh.

    You can use categories to extend an existing HasTraits class, as an
    alternative to subclassing. An advantage of categories over subclassing is
    that you can access the added members on instances of the original class,
    without having to change them to instances of a subclass. Unlike
    subclassing, categories do not allow overriding trait attributes.
é    )Úabsolute_importNé   )ÚMetaHasTraitsÚupdate_traits_class_dictÚ
BaseTraitsÚClassTraitsÚInstanceTraitsÚPrefixTraitsÚListenerTraitsÚ
ViewTraitsc               @   s   e Zd Zdd„ ZdS )ÚMetaCategoryc             C   s¶   t |ƒdkrtdƒ‚t|||dd� t |ƒdkr¦|d }|j|jtƒ|jtƒ|jtƒ|jtƒ|jt	ƒ|jt
ƒƒ x4t|jƒ ƒD ]$\}}t||ƒs~t|||ƒ ||= q~W tj| |||ƒS )Né   z2Correct usage is: class FooCategory(Category,Foo):T)Zis_categoryr   )ÚlenÚ	TypeErrorr   Z_add_trait_categoryÚpopr   r   r   r	   r
   r   ÚlistÚitemsÚhasattrÚsetattrÚtypeÚ__new__)ÚclsÚ
class_nameÚbasesÚ
class_dictZcategory_classÚnameÚvalue© r   ú3/tmp/pip-install-5sebvq2j/traits/traits/category.pyr   5   s&    

zMetaCategory.__new__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   4   s   r   c               @   s   e Zd ZdZdS )ÚCategoryaä   Used for defining "category" extensions to existing classes.

    To define a class as a category, specify "Category," followed by the name
    of the base class name in the base class list.

    The following example demonstrates defining a category::

        from traits.api import HasTraits, Str, Category

        class Base(HasTraits):
            x = Str("Base x")
            y = Str("Base y")

        class BaseExtra(Category, Base):
            z = Str("BaseExtra z")
    N)r   r    r!   Ú__doc__r   r   r   r   r"   _   s   r"   )r#   Ú
__future__r   ÚsixZ
has_traitsr   r   r   r   r   r	   r
   r   r   Úadd_metaclassÚobjectr"   r   r   r   r   Ú<module>   s   (+