← Back
Editing: _properties_compat.cpython-311.pyc
� %�c. � �: � G d � d� � Z G d� d� � ZdS )c � � e Zd ZdZd� Zdd�ZdS )�NonDataPropertya� Much like the property builtin, but only implements __get__, making it a non-data property, and can be subsequently reset. See http://users.rcn.com/python/download/Descriptor.htm for more information. >>> class X(object): ... @NonDataProperty ... def foo(self): ... return 3 >>> x = X() >>> x.foo 3 >>> x.foo = 4 >>> x.foo 4 c �^ � |� J d� � �t |� � s J d� � �|| _ d S )Nzfget cannot be nonezfget must be callable)�callable�fget)�selfr s �</usr/lib/python3/dist-packages/keyring/_properties_compat.py�__init__zNonDataProperty.__init__ s= � ����!6������~�~�6�6�6�6�6�6��� � � � Nc �4 � |�| S | � |� � S �N)r )r �obj�objtypes r �__get__zNonDataProperty.__get__ s � ��;��K��y�y��~�~�r r )�__name__� __module__�__qualname__�__doc__r r � r r r r sA � � � � � �� �$� � � � � � � � r r c �` � e Zd ZdZ G d� de� � Zd d�Zd d�Zd� Zd� Z e d � � � ZdS )� classpropertya� Like @property but applies at the class level. >>> class X(metaclass=classproperty.Meta): ... val = None ... @classproperty ... def foo(cls): ... return cls.val ... @foo.setter ... def foo(cls, val): ... cls.val = val >>> X.foo >>> X.foo = 3 >>> X.foo 3 >>> x = X() >>> x.foo 3 >>> X.foo = 4 >>> x.foo 4 Setting the property on an instance affects the class. >>> x.foo = 5 >>> x.foo 5 >>> X.foo 5 >>> vars(x) {} >>> X().foo 5 Attempting to set an attribute where no setter was defined results in an AttributeError: >>> class GetOnly(metaclass=classproperty.Meta): ... @classproperty ... def foo(cls): ... return 'bar' >>> GetOnly.foo = 3 Traceback (most recent call last): ... AttributeError: can't set attribute It is also possible to wrap a classmethod or staticmethod in a classproperty. >>> class Static(metaclass=classproperty.Meta): ... @classproperty ... @classmethod ... def foo(cls): ... return 'foo' ... @classproperty ... @staticmethod ... def bar(): ... return 'bar' >>> Static.foo 'foo' >>> Static.bar 'bar' *Legacy* For compatibility, if the metaclass isn't specified, the legacy behavior will be invoked. >>> class X: ... val = None ... @classproperty ... def foo(cls): ... return cls.val ... @foo.setter ... def foo(cls, val): ... cls.val = val >>> X.foo >>> X.foo = 3 >>> X.foo 3 >>> x = X() >>> x.foo 3 >>> X.foo = 4 >>> x.foo 4 Note, because the metaclass was not specified, setting a value on an instance does not have the intended effect. >>> x.foo = 5 >>> x.foo 5 >>> X.foo # should be 5 4 >>> vars(x) # should be empty {'foo': 5} >>> X().foo # should be 5 4 c � � � e Zd Z� fd�Z� xZS )�classproperty.Metac �� �� | j � |d � � }t |� � t u r|� | |� � S t � � � ||� � S r )�__dict__�get�typer �__set__�super�__setattr__)r �key�valuer � __class__s �r r zclassproperty.Meta.__setattr__� sY �� ��-�#�#�C��.�.�C��C�y�y�M�)�)��{�{�4��/�/�/��7�7�&�&�s�E�2�2�2r )r r r r � __classcell__)r"