`L i :ddlmZmZddlmZGddZdZy))update_wrapperwraps) MethodTypec$eZdZdZdZdZddZy)_AvailableIfDescriptoravImplements a conditional property using the descriptor protocol. Using this class to create a decorator will raise an ``AttributeError`` if check(self) returns a falsey value. Note that if check raises an error this will also result in hasattr returning false. See https://docs.python.org/3/howto/descriptor.html for an explanation of descriptors. cF||_||_||_t||yN)fncheckattribute_namer)selfr r r s a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sklearn/utils/_available_if.py__init__z_AvailableIfDescriptor.__init__s$ , tR cd|jd|j} |j|}|s t |y#t$r}t ||d}~wwxYw)NzThis z has no attribute )__name__r r ExceptionAttributeError)r objowner attr_err_msg check_resultes r_checkz_AvailableIfDescriptor._checksjENN%%78K8K7N O  6::c?L . . 6 .A 5 6s= A AANc|+j|tj|}|Stjfd}|S)NrcTj|dj|i|S)Nrr)rr )argskwargsrr s routz+_AvailableIfDescriptor.__get__..out1s- DG5 1tww///r)rrr r)r rrr s` ` r__get__z_AvailableIfDescriptor.__get__'sT ? KK5K )TWWc*C 477^ 0 0 rr )r __module__ __qualname____doc__rrr!rrrrs! /rrcfdS)aAn attribute that is available only if check returns a truthy value. Parameters ---------- check : callable When passed the object with the decorated method, this should return a truthy value if the attribute is available, and either return False or raise an AttributeError if not available. Returns ------- callable Callable makes the decorated method available if `check` returns a truthy value, otherwise the decorated method is unavailable. Examples -------- >>> from sklearn.utils.metaestimators import available_if >>> class HelloIfEven: ... def __init__(self, x): ... self.x = x ... ... def _x_is_even(self): ... return self.x % 2 == 0 ... ... @available_if(_x_is_even) ... def say_hello(self): ... print("Hello") ... >>> obj = HelloIfEven(1) >>> hasattr(obj, "say_hello") False >>> obj.x = 2 >>> hasattr(obj, "say_hello") True >>> obj.say_hello() Hello c4t||jS)N)r )rr)r r s rzavailable_if..`s,Rr{{Srr%)r s`r available_ifr)9s N TSrN) functoolsrrtypesrrr)r%rrr,s,..b'Tr