Coverage for pygeodesy/props.py : 97%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
for C{DeprecationWarning}s.
To enable C{DepreactionWarning}s from C{PyGeodesy}, set environment variable C{PYGEODESY_WARNINGS} to a non-empty string. For more details see function L{DeprecationWarnings} below. ''' _xkwds _invalid_, _N_A_, _SPACE_ # _UNDER_
# _PYTHON_X_DEV or bool(_sys.warnoptions)
'''(INTERNAL) Check whether C{inst} has a C{P/property/_RO} by this C{name}. ''' return False
'''(INTERNAL) Zap all I{cached} L{property_RO}s, L{Property_RO}s and the named C{attrs} from an instance' C{__dict__}.
@return: The number of updates (C{int}), if any. '''
if hasattr(inst, a): d.pop(a, None) else: # PYCHOK no cover from pygeodesy.named import classname n = classname(inst, prefixed=True) a = _DOT_(n, _SPACE_(a, _invalid_)) raise _AssertionError(a, txt=repr(inst))
'''(INTERNAL) Base class for C{P/property/_RO}. '''
self.getter(method) # PYCHOK no cover
self.__doc__ = d # PYCHOK no cover
self._update(inst, None) # PYCHOK no cover
# cache the value in the instance' __dict__
'''Throws an C{AttributeError}, always. '''
raise _AttributeError(e, txt=name)
raise _AttributeError(e, txt=name)
'''(INTERNAL) Zap the I{cached} C{inst.__dict__[name]} item. '''
'''Throws an C{AttributeError}, always. '''
'''Throws an C{AttributeError}, always. '''
'''Throws an C{AttributeError}, always. '''
# No __doc__ on purpose '''New I{immutable}, I{caching}, I{memoizing} C{property} I{Factory} to be used as C{decorator}.
@arg method: The callable being decorated as this C{property}'s C{getter}, to be invoked only once. @kwarg doc: Optional property documentation (C{str}).
@note: Like standard Python C{property} without a C{setter}, but with a more descriptive error message when set.
@see: Python 3's U{functools.cached_property<https://docs.Python.org/3/ library/functools.html#functools.cached_property>} and U{-.cache <https://Docs.Python.org/3/library/functools.html#functools.cache>} to I{cache} or I{memoize} the property value.
@see: Luciano Ramalho, "Fluent Python", page 636, O'Reilly, 2016, "Coding a Property Factory", especially Example 19-24 and U{class Property<https://docs.Python.org/3/howto/descriptor.html>}. '''
# No __doc__ on purpose '''New I{mutable}, I{caching}, I{memoizing} C{property} I{Factory} to be used as C{decorator}.
@see: L{Property_RO} for more details.
@note: Unless and until the C{setter} is defined, this L{Property} behaves like an I{immutable}, I{caching}, I{memoizing} L{Property_RO}. '''
'''Make this C{Property} I{mutable}.
@arg method: The callable being decorated as this C{Property}'s C{setter}.
@note: Setting a new property value always clears the previously I{cached} or I{memoized} value I{after} invoking the B{C{method}}. ''' _PropertyBase.setter(self, method) # PYCHOK no cover
# class Property <https://docs.Python.org/3/howto/descriptor.html>
# No __doc__ on purpose '''New I{immutable}, standard C{property} to be used as C{decorator}.
@arg method: The callable being decorated as C{property}'s C{getter}. @kwarg doc: Optional property documentation (C{str}).
@note: Like standard Python C{property} without a setter, but with a more descriptive error message when set.
@see: L{Property_RO}. '''
'''DEPRECATED (INTERNAL) Zap the I{cached} C{inst.__dict__[_name]} item. ''' # if _W_DEV: # _n = _qualify(self, self._update.__name__) # _throwarning(_method_, _n, _dont_use_) # c = clas or inst.__class__ # if c: # _n = NN(_UNDER_, self.name) # if c.__dict__.get(_n, False) is None: # in (None, ()): # inst.__dict__.pop(_n, None)
'''Decorator for a standard C{property} with basic documentation.
@arg doc: The property documentation (C{str}).
@example:
>>> @property_doc_("documentation text.") >>> def name(self): >>> ... >>> >>> @name.setter >>> def name(self, value): >>> ... ''' # See Luciano Ramalho, "Fluent Python", page 212ff, O'Reilly, 2016, # "Parameterized Decorators", especially Example 7-23. Also, see # <https://Python-3-Patterns-Idioms-Test.ReadTheDocs.io/en/latest/PythonDecorators.html>
'''(INTERNAL) Return the documented C{property}. '''
'''(INTERNAL) Decorator for DEPRECATED functions, methods, etc.
@see: Brett Slatkin, "Effective Python", page 105, 2nd ed, Addison-Wesley, 2019. '''
elif args: # method q = _qualify(args[0], call.__name__) # PYCHOK no cover else: # just in case q = call.__name__ # PYCHOK no cover
'''Decorator for a DEPRECATED class.
@arg Clas: The class (C{class}).
@return: The B{C{Clas}} DEPRECATED. '''
# @_wraps(Clas) # XXX?
def __init__(self, *args, **kwds): # PYCHOK no cover _throwarning('class', q_d, doc) Clas.__init__(self, *args, **kwds)
else: return Clas
'''Decorator for a DEPRECATED function.
@arg call: The deprecated function (C{callable}).
@return: The B{C{call}} DEPRECATED. ''' call.__module__, call.__name__)) if \ _W_DEV else call
'''Decorator for a DEPRECATED method.
@arg call: The deprecated method (C{callable}).
@return: The B{C{call}} DEPRECATED. '''
def _deprecated_module(name): # PYCHOK no cover '''(INTERNAL) Callable within a DEPRECATED module. ''' if _W_DEV: _throwarning('module', name, _dont_use_)
'''Decorator for a DEPRECATED L{Property_RO}.
@arg method: The C{Property_RO.fget} method (C{callable}).
@return: The B{C{method}} DEPRECATED. '''
'''Decorator for a DEPRECATED L{property_RO}.
@arg method: The C{property_RO.fget} method (C{callable}).
@return: The B{C{method}} DEPRECATED. '''
'''(INTERNAL) Create a DEPRECATED C{property_RO} or C{Property_RO}. '''
def _fget(self, inst): # PYCHOK no cover q = _qualify(inst, self.name) # method.__name__ _throwarning(_RO.__name__, q, doc) return self.method(inst)
else: return _RO(method, doc=doc) # PYCHOK no cover
'''Get the C{DeprecationWarning}s reported or raised.
@return: The number of C{DeprecationWarning}s (C{int}) or C{0}.
@note: To get L{DeprecationWarnings} if any, run C{python} with environment variable C{PYGEODESY_WARNINGS} set to a non-empty string AND use C{python} command line option C{-X dev}, C{-W always}, C{-W error}, etc. '''
'''(INTERNAL) Get uniform DEPRECATED __doc__ string. ''' except AttributeError: # PYCHOK no cover i = -1
def _qualify(inst, name): # PYCHOK no cover '''(INTERNAL) Fully qualify a name. ''' # _DOT_(inst.classname, name), not _DOT_(inst.named4, name) c = inst.__class__ q = _DOT_(c.__module__, c.__name__, name) return q
'''(INTERNAL) Report or raise a C{DeprecationWarning}. ''' global _Warnings # XXX _warn or raise DeprecationWarning(text)
# **) MIT License # # Copyright (C) 2016-2021 -- mrJean1 at Gmail -- All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. |