objetto
Advanced tools
| # -*- coding: utf-8 -*- | ||
| """Python-2 compatile way of finding a qualified name of a class/method.""" | ||
| import ast | ||
| import inspect | ||
| from typing import TYPE_CHECKING | ||
| if TYPE_CHECKING: | ||
| from typing import Callable | ||
| __all__ = ["qualname"] | ||
| _cache = {} # type: ignore | ||
| class _Visitor(ast.NodeVisitor): | ||
| def __init__(self): | ||
| self.stack = [] | ||
| self.qualnames = {} | ||
| def store_qualname(self, lineno): | ||
| qn = ".".join(n for n in self.stack) | ||
| self.qualnames[lineno] = qn | ||
| def visit_FunctionDef(self, node): | ||
| self.stack.append(node.name) | ||
| self.store_qualname(node.lineno) | ||
| self.stack.append("<locals>") | ||
| self.generic_visit(node) | ||
| self.stack.pop() | ||
| self.stack.pop() | ||
| def visit_ClassDef(self, node): | ||
| self.stack.append(node.name) | ||
| self.store_qualname(node.lineno) | ||
| self.generic_visit(node) | ||
| self.stack.pop() | ||
| def qualname(obj): | ||
| # type: (Callable) -> str | ||
| """ | ||
| Find out the qualified name for a class or function. | ||
| :param obj: Function or class. | ||
| :type obj: function or type | ||
| :return: Qualified name. | ||
| :rtype: str | ||
| :raises AttributeError: Raised when couldn't get qualified name. | ||
| """ | ||
| # For Python 3.3+, this is straight-forward. | ||
| if hasattr(obj, "__qualname__"): | ||
| return obj.__qualname__ | ||
| # For older Python versions, things get complicated. | ||
| # Obtain the filename and the line number where the | ||
| # class/method/function is defined. | ||
| try: | ||
| filename = inspect.getsourcefile(obj) | ||
| except TypeError: | ||
| return obj.__qualname__ # raises a sensible error | ||
| if inspect.isclass(obj): | ||
| try: | ||
| _, lineno = inspect.getsourcelines(obj) | ||
| except (OSError, IOError): | ||
| return obj.__qualname__ # raises a sensible error | ||
| elif inspect.isfunction(obj) or inspect.ismethod(obj): | ||
| if hasattr(obj, "im_func"): | ||
| # Extract function from unbound method (Python 2) | ||
| obj = obj.im_func # type: ignore | ||
| try: | ||
| code = obj.__code__ | ||
| except AttributeError: | ||
| code = obj.func_code # type: ignore | ||
| lineno = code.co_firstlineno | ||
| else: | ||
| return obj.__qualname__ # raises a sensible error | ||
| # Re-parse the source file to figure out what the | ||
| # __qualname__ should be by analysing the abstract | ||
| # syntax tree. Use a cache to avoid doing this more | ||
| # than once for the same file. | ||
| qualnames = _cache.get(filename) | ||
| if qualnames is None: | ||
| if filename is None: | ||
| return obj.__qualname__ # raises a sensible error | ||
| with open(filename, "r") as fp: | ||
| source = fp.read() | ||
| node = ast.parse(source, filename) | ||
| visitor = _Visitor() | ||
| visitor.visit(node) | ||
| _cache[filename] = qualnames = visitor.qualnames | ||
| try: | ||
| return qualnames[lineno] | ||
| except KeyError: | ||
| return obj.__qualname__ # raises a sensible error |
| # -*- coding: utf-8 -*- | ||
| """Decorator to simplify exception traceback when used with wrapped functions.""" | ||
| import inspect | ||
| from functools import wraps | ||
| from sys import _getframe, exc_info | ||
| from typing import TYPE_CHECKING | ||
| from six import PY2 | ||
| if TYPE_CHECKING: | ||
| from typing import Callable, TypeVar | ||
| RT = TypeVar("RT") # Return type. | ||
| __all__ = ["simplify_exceptions"] | ||
| if PY2: | ||
| def exec_(_code_, _globs_=None, _locs_=None): | ||
| """Execute code in a namespace.""" | ||
| if _globs_ is None: | ||
| frame = _getframe(1) | ||
| _globs_ = frame.f_globals | ||
| if _locs_ is None: | ||
| _locs_ = frame.f_locals | ||
| del frame | ||
| elif _locs_ is None: | ||
| _locs_ = _globs_ | ||
| exec("""exec _code_ in _globs_, _locs_""") | ||
| else: | ||
| exec_ = None | ||
| def simplify_exceptions(func): | ||
| # type: (Callable[..., RT]) -> Callable[..., RT] | ||
| """ | ||
| To be used with a wrapped function. | ||
| This will simplify the exception traceback by chopping up two levels of it. | ||
| .. code:: python | ||
| >>> from functools import wraps | ||
| >>> from objetto.utils.simplify_exceptions import simplify_exceptions | ||
| >>> def my_decorator(f): | ||
| ... @wraps(f) | ||
| ... @simplify_exceptions | ||
| ... def _wrapped(*args, **kwargs): | ||
| ... return f(*args, **kwargs) # will be excluded from the traceback | ||
| ... return _wrapped | ||
| ... | ||
| >>> @my_decorator | ||
| ... def my_function(): | ||
| ... raise ValueError("oops; something is wrong") | ||
| ... | ||
| >>> my_function() | ||
| Traceback (most recent call last): | ||
| ValueError: oops; something is wrong | ||
| :param func: Function to be decorated. | ||
| :type func: function | ||
| :return: Decorated function. | ||
| :rtype: function | ||
| """ | ||
| @wraps(func) | ||
| def _decorated(*args, **kwargs): | ||
| try: | ||
| return func(*args, **kwargs) | ||
| except Exception as exc: | ||
| exc_type, exc_value, exc_traceback = exc_info() | ||
| # Re-raise without change if exception has custom arguments. | ||
| try: | ||
| args = inspect.getfullargspec(exc_type.__init__).args # type: ignore | ||
| except AttributeError: | ||
| try: | ||
| # noinspection PyDeprecation | ||
| args = inspect.getargspec(exc_type.__init__).args # type: ignore | ||
| except TypeError: | ||
| args = ["self"] | ||
| if len(args) != 1: | ||
| raise | ||
| # Chop the traceback and remove the decorated bits. | ||
| try: | ||
| exc_traceback = exc_traceback.tb_next | ||
| exc_traceback = exc_traceback.tb_next | ||
| except Exception: | ||
| pass | ||
| # Re-raise exception with the chopped traceback. | ||
| if PY2: | ||
| assert exec_ is not None | ||
| exec_("""raise exc_type, exc_value, exc_traceback""") | ||
| else: | ||
| if exc.__traceback__ is not exc_traceback: | ||
| raise exc.with_traceback(exc_traceback) | ||
| else: | ||
| raise exc | ||
| return _decorated |
| # -*- coding: utf-8 -*- | ||
| import pytest | ||
| from six import with_metaclass | ||
| from objetto import Data, data_constant_attribute | ||
| def test_attribute_type_check(): | ||
| class CustomMeta(type): | ||
| pass | ||
| class Custom(with_metaclass(CustomMeta, object)): | ||
| pass | ||
| class MyData(Data): | ||
| CustomType = data_constant_attribute(Custom, abstracted=True, subtypes=True) | ||
| class OtherCustomMeta(CustomMeta): | ||
| pass | ||
| class OtherCustom(with_metaclass(OtherCustomMeta, Custom)): | ||
| pass | ||
| class MyOtherData(MyData): | ||
| CustomType = OtherCustom | ||
| assert MyOtherData | ||
| if __name__ == "__main__": | ||
| pytest.main() |
| # -*- coding: utf-8 -*- | ||
| from typing import TYPE_CHECKING, cast | ||
| import pytest | ||
| from pyrsistent import PClass, field | ||
| from objetto import Application, Object, attribute | ||
| if TYPE_CHECKING: | ||
| from typing import Union # noqa | ||
| else: | ||
| reveal_type = lambda *_: None | ||
| def test_list_object(): | ||
| # type: () -> None | ||
| app = Application() | ||
| person = _Person(app, name="Albert", age=36, something=999) | ||
| reveal_type(person.name) | ||
| reveal_type(person.age) | ||
| reveal_type(person.something) | ||
| p_person = _PPerson(name="Albert", age=36, something=999) | ||
| reveal_type(p_person.name) | ||
| reveal_type(p_person.age) | ||
| reveal_type(p_person.something) | ||
| class _Person(Object): | ||
| name = attribute(str) | ||
| age = attribute(int) | ||
| something = cast("Union[int, str]", attribute((int, str))) | ||
| class _PPerson(PClass): | ||
| name = field(str) | ||
| age = field(int) | ||
| something = cast("Union[int, str]", field((int, str))) | ||
| if __name__ == "__main__": | ||
| pytest.main() |
| Metadata-Version: 2.1 | ||
| Name: objetto | ||
| Version: 1.28.0 | ||
| Version: 1.29.0 | ||
| Summary: Object-oriented framework for building smart applications and APIs | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/brunonicko/objetto |
@@ -1,4 +0,2 @@ | ||
| decorator | ||
| pyrsistent | ||
| qualname | ||
| six | ||
@@ -5,0 +3,0 @@ slotted |
@@ -73,4 +73,6 @@ LICENSE | ||
| objetto/utils/list_operations.py | ||
| objetto/utils/qualname.py | ||
| objetto/utils/recursive_repr.py | ||
| objetto/utils/reraise_context.py | ||
| objetto/utils/simplify_exceptions.py | ||
| objetto/utils/storage.py | ||
@@ -86,2 +88,4 @@ objetto/utils/subject_observer.py | ||
| tests/test_reactions.py | ||
| tests/test_type_compatibility.py | ||
| tests/test_typing.py | ||
| tests/test_utils_caller_module.py | ||
@@ -88,0 +92,0 @@ tests/test_utils_custom_repr.py |
+23
-31
@@ -19,3 +19,3 @@ # -*- coding: utf-8 -*- | ||
| from ._constants import BASE_STRING_TYPES, STRING_TYPES | ||
| from ._data import BaseData, DataAttribute, InteractiveDictData | ||
| from ._data import BaseData, InteractiveDictData | ||
| from ._exceptions import BaseObjettoException | ||
@@ -270,5 +270,3 @@ from ._states import BaseState, DictState | ||
| state = data_attribute( | ||
| BaseState, subtypes=True, checked=False | ||
| ) # type: DataAttribute[BaseState] | ||
| state = data_attribute(BaseState, subtypes=True, checked=False) # type: BaseState | ||
| """State.""" | ||
@@ -278,3 +276,3 @@ | ||
| (BaseData, None), subtypes=True, checked=False | ||
| ) # type: DataAttribute[Optional[BaseData]] | ||
| ) # type: Optional[BaseData] | ||
| """Data.""" | ||
@@ -284,3 +282,3 @@ | ||
| key_types=STRING_TYPES, checked=False | ||
| ) # type: DataAttribute[InteractiveDictData[str, Any]] | ||
| ) # type: InteractiveDictData[str, Any] | ||
| """Metadata.""" | ||
@@ -292,3 +290,3 @@ | ||
| default=WeakReference(), | ||
| ) # type: DataAttribute[WeakReference[BaseObject]] | ||
| ) # type: WeakReference[BaseObject] | ||
| """Weak reference to the parent.""" | ||
@@ -300,3 +298,3 @@ | ||
| default=WeakReference(), | ||
| ) # type: DataAttribute[WeakReference[BaseObject]] | ||
| ) # type: WeakReference[BaseObject] | ||
| """Weak reference to the history provider.""" | ||
@@ -308,3 +306,3 @@ | ||
| default=WeakReference(), | ||
| ) # type: DataAttribute[WeakReference[HistoryObject]] | ||
| ) # type: WeakReference[HistoryObject] | ||
| """Weak reference to the last history object.""" | ||
@@ -314,9 +312,8 @@ | ||
| (".._history|HistoryObject", None), checked=False, default=None | ||
| ) # type: DataAttribute[HistoryObject] | ||
| ) # type: HistoryObject | ||
| """History object.""" | ||
| children = cast( | ||
| "DataAttribute[InteractiveSetData[BaseObject]]", | ||
| data_set_attribute(".._objects|BaseObject", subtypes=True, checked=False), | ||
| ) # type: DataAttribute[InteractiveSetData[BaseObject]] | ||
| children = data_set_attribute( | ||
| ".._objects|BaseObject", subtypes=True, checked=False | ||
| ) # type: InteractiveSetData[BaseObject] | ||
| """Children.""" | ||
@@ -336,3 +333,3 @@ | ||
| ".._objects|BaseObject", subtypes=True, checked=False | ||
| ) # type: DataAttribute[BaseObject] | ||
| ) # type: BaseObject | ||
| """ | ||
@@ -346,3 +343,3 @@ Object where the action originated from (where the change happened). | ||
| ".._objects|BaseObject", subtypes=True, checked=False | ||
| ) # type: DataAttribute[BaseObject] | ||
| ) # type: BaseObject | ||
| """ | ||
@@ -354,5 +351,3 @@ Object relaying the action up the hierarchy. | ||
| locations = data_protected_list_attribute( | ||
| checked=False | ||
| ) # type: DataAttribute[ListData[Any]] | ||
| locations = data_protected_list_attribute(checked=False) # type: ListData[Any] | ||
| """ | ||
@@ -366,3 +361,3 @@ List of relative locations from the receiver to the sender. | ||
| BaseChange, subtypes=True, checked=False | ||
| ) # type: DataAttribute[BaseChange] | ||
| ) # type: BaseChange | ||
| """ | ||
@@ -380,14 +375,11 @@ Change that happened in the sender. | ||
| Action, checked=False, finalized=True | ||
| ) # type: Final[DataAttribute[ListData[Action]]] | ||
| ) # type: Final[ListData[Action]] | ||
| """Actions.""" | ||
| stores = cast( | ||
| "DataAttribute[DictData[BaseObject, Store]]", | ||
| data_protected_dict_attribute( | ||
| Store, | ||
| checked=False, | ||
| key_types=".._objects|BaseObject", | ||
| key_subtypes=True, | ||
| ), | ||
| ) # type: Final[DataAttribute[DictData[BaseObject, Store]]] | ||
| stores = data_protected_dict_attribute( | ||
| Store, | ||
| checked=False, | ||
| key_types=".._objects|BaseObject", | ||
| key_subtypes=True, | ||
| ) # type: Final[DictData[BaseObject, Store]] | ||
| """Modified stores.""" | ||
@@ -400,3 +392,3 @@ | ||
| phase = data_attribute(Phase, checked=False) # type: DataAttribute[Phase] | ||
| phase = data_attribute(Phase, checked=False) # type: Phase | ||
| """Batch phase.""" | ||
@@ -403,0 +395,0 @@ |
+23
-16
@@ -6,2 +6,3 @@ # -*- coding: utf-8 -*- | ||
| from contextlib import contextmanager | ||
| from functools import wraps | ||
| from inspect import getmro | ||
@@ -28,4 +29,2 @@ from typing import TYPE_CHECKING, Callable, Generic, Type, TypeVar, cast | ||
| from decorator import decorator | ||
| from qualname import qualname # type: ignore | ||
| from six import iteritems, with_metaclass | ||
@@ -42,2 +41,5 @@ from slotted import ( | ||
| from ..utils.qualname import qualname | ||
| from ..utils.simplify_exceptions import simplify_exceptions | ||
| if TYPE_CHECKING: | ||
@@ -88,2 +90,3 @@ from typing import ( | ||
| T = TypeVar("T") # Any type. | ||
| RT = TypeVar("RT") # Return type. | ||
| KT = TypeVar("KT") # Key type. | ||
@@ -169,10 +172,9 @@ VT = TypeVar("VT") # Value type. | ||
| @decorator | ||
| def final_(obj_, *args, **kwargs): | ||
| """Decorator for final methods.""" | ||
| return obj_(*args, **kwargs) | ||
| @wraps(obj) | ||
| @simplify_exceptions | ||
| def _decorated(*args, **kwargs): | ||
| return obj(*args, **kwargs) | ||
| decorated = final_(obj) | ||
| object.__setattr__(decorated, FINAL_METHOD_TAG, True) | ||
| return __final(decorated) | ||
| object.__setattr__(_decorated, FINAL_METHOD_TAG, True) | ||
| return __final(_decorated) | ||
@@ -243,5 +245,4 @@ | ||
| @decorator | ||
| def init(func, *args, **kwargs): | ||
| # type: (F, Any, Any) -> F | ||
| def init(func): | ||
| # type: (Callable[..., RT]) -> Callable[..., RT] | ||
| """ | ||
@@ -279,8 +280,14 @@ Method decorator that sets the initializing tag for :class:`objetto.bases.Base` | ||
| """ | ||
| self = args[0] | ||
| with init_context(self): | ||
| result = func(*args, **kwargs) | ||
| return result | ||
| @wraps(func) | ||
| @simplify_exceptions | ||
| def _decorated(*args, **kwargs): | ||
| self = args[0] | ||
| with init_context(self): | ||
| result = func(*args, **kwargs) | ||
| return result | ||
| return _decorated | ||
| # noinspection PyTypeChecker | ||
@@ -287,0 +294,0 @@ _B = TypeVar("_B", bound="Base") |
@@ -12,3 +12,2 @@ # -*- coding: utf-8 -*- | ||
| from qualname import qualname # type: ignore | ||
| from slotted import SlottedMutableSequence, SlottedSequence | ||
@@ -15,0 +14,0 @@ |
+51
-77
@@ -21,3 +21,3 @@ # -*- coding: utf-8 -*- | ||
| from ._data import DataAttribute, DictData, ListData, SetData | ||
| from ._data import DictData, ListData, SetData | ||
| from ._history import HistoryObject | ||
@@ -53,5 +53,3 @@ from ._objects import BaseObject | ||
| name = data_attribute( | ||
| STRING_TYPES, checked=False, abstracted=True | ||
| ) # type: DataAttribute[str] | ||
| name = data_attribute(STRING_TYPES, checked=False, abstracted=True) # type: str | ||
| """ | ||
@@ -65,3 +63,3 @@ Name describing the change. | ||
| ".._objects|BaseObject", subtypes=True, checked=False, finalized=True | ||
| ) # type: Final[DataAttribute[BaseObject]] | ||
| ) # type: Final[BaseObject] | ||
| """ | ||
@@ -73,5 +71,3 @@ Object being changed. | ||
| is_atomic = data_constant_attribute( | ||
| False, abstracted=True | ||
| ) # type: DataAttribute[bool] | ||
| is_atomic = data_constant_attribute(False, abstracted=True) # type: bool | ||
| """ | ||
@@ -104,3 +100,3 @@ Whether change is atomic or not. | ||
| finalized=True, compared=False, serialized=False, represented=False | ||
| ) # type: Final[DataAttribute[Callable]] | ||
| ) # type: Final[Callable] | ||
| """Redo delegate.""" | ||
@@ -110,3 +106,3 @@ | ||
| finalized=True, compared=False, serialized=False, represented=False | ||
| ) # type: Final[DataAttribute[Callable]] | ||
| ) # type: Final[Callable] | ||
| """Undo delegate.""" | ||
@@ -116,3 +112,3 @@ | ||
| BaseState, subtypes=True, checked=False, finalized=True | ||
| ) # type: Final[DataAttribute[BaseState]] | ||
| ) # type: Final[BaseState] | ||
| """ | ||
@@ -126,3 +122,3 @@ Object state before the change. | ||
| BaseState, subtypes=True, checked=False, finalized=True | ||
| ) # type: Final[DataAttribute[BaseState]] | ||
| ) # type: Final[BaseState] | ||
| """ | ||
@@ -139,3 +135,3 @@ Object state after the change. | ||
| finalized=True, | ||
| ) # type: Final[DataAttribute[SetData[BaseObject]]] | ||
| ) # type: Final[SetData[BaseObject]] | ||
| """ | ||
@@ -152,3 +148,3 @@ Children objects being released. | ||
| finalized=True, | ||
| ) # type: Final[DataAttribute[SetData[BaseObject]]] | ||
| ) # type: Final[SetData[BaseObject]] | ||
| """ | ||
@@ -165,3 +161,3 @@ Children objects being adopted. | ||
| finalized=True, | ||
| ) # type: Final[DataAttribute[SetData[BaseObject]]] | ||
| ) # type: Final[SetData[BaseObject]] | ||
| """ | ||
@@ -179,3 +175,3 @@ Objects adopting the history from the object being changed. | ||
| default=None, | ||
| ) # type: Final[DataAttribute[Optional[HistoryObject]]] | ||
| ) # type: Final[Optional[HistoryObject]] | ||
| """ | ||
@@ -187,5 +183,3 @@ History where this changed originated from (result of an redo/undo operation). | ||
| is_atomic = data_constant_attribute( | ||
| True, finalized=True | ||
| ) # type: DataAttribute[bool] | ||
| is_atomic = data_constant_attribute(True, finalized=True) # type: bool | ||
| """ | ||
@@ -207,3 +201,3 @@ Whether change is atomic or not. | ||
| name = data_attribute(STRING_TYPES, checked=False) # type: DataAttribute[str] | ||
| name = data_attribute(STRING_TYPES, checked=False) # type: str | ||
| """ | ||
@@ -217,3 +211,3 @@ Name describing the change. | ||
| key_types=STRING_TYPES, checked=False | ||
| ) # type: DataAttribute[DictData[str, Any]] | ||
| ) # type: DictData[str, Any] | ||
| """ | ||
@@ -225,5 +219,3 @@ Metadata. | ||
| is_atomic = data_constant_attribute( | ||
| False, finalized=True | ||
| ) # type: DataAttribute[bool] | ||
| is_atomic = data_constant_attribute(False, finalized=True) # type: bool | ||
| """ | ||
@@ -247,3 +239,3 @@ Whether change is atomic or not. | ||
| STRING_TYPES, checked=False, default="Update Attributes" | ||
| ) # type: DataAttribute[str] | ||
| ) # type: str | ||
| """ | ||
@@ -257,3 +249,3 @@ Name describing the change. | ||
| checked=False, key_types=STRING_TYPES | ||
| ) # type: DataAttribute[DictData[str, Any]] | ||
| ) # type: DictData[str, Any] | ||
| """ | ||
@@ -267,3 +259,3 @@ Old attribute values. | ||
| checked=False, key_types=STRING_TYPES | ||
| ) # type: DataAttribute[DictData[str, Any]] | ||
| ) # type: DictData[str, Any] | ||
| """ | ||
@@ -287,3 +279,3 @@ New attribute values. | ||
| STRING_TYPES, checked=False, default="Update Values" | ||
| ) # type: DataAttribute[str] | ||
| ) # type: str | ||
| """ | ||
@@ -295,3 +287,3 @@ Name describing the change. | ||
| checked=False | ||
| ) # type: DataAttribute[DictData[Any, Any]] | ||
| ) # type: DictData[Any, Any] | ||
| """ | ||
@@ -305,3 +297,3 @@ Old values. | ||
| checked=False | ||
| ) # type: DataAttribute[DictData[Any, Any]] | ||
| ) # type: DictData[Any, Any] | ||
| """ | ||
@@ -325,3 +317,3 @@ New values. | ||
| STRING_TYPES, checked=False, default="Insert Values" | ||
| ) # type: DataAttribute[str] | ||
| ) # type: str | ||
| """ | ||
@@ -333,3 +325,3 @@ Name describing the change. | ||
| index = data_attribute(INTEGER_TYPES, checked=False) # type: DataAttribute[int] | ||
| index = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -341,5 +333,3 @@ Insertion index. | ||
| last_index = data_attribute( | ||
| INTEGER_TYPES, checked=False | ||
| ) # type: DataAttribute[int] | ||
| last_index = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -351,3 +341,3 @@ Last inserted value index. | ||
| stop = data_attribute(INTEGER_TYPES, checked=False) # type: DataAttribute[int] | ||
| stop = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -361,3 +351,3 @@ Stop index. | ||
| checked=False, | ||
| ) # type: DataAttribute[ListData[Any]] | ||
| ) # type: ListData[Any] | ||
| """ | ||
@@ -381,3 +371,3 @@ New values. | ||
| STRING_TYPES, checked=False, default="Remove Values" | ||
| ) # type: DataAttribute[str] | ||
| ) # type: str | ||
| """ | ||
@@ -389,3 +379,3 @@ Name describing the change. | ||
| index = data_attribute(INTEGER_TYPES, checked=False) # type: DataAttribute[int] | ||
| index = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -397,5 +387,3 @@ First removed value index. | ||
| last_index = data_attribute( | ||
| INTEGER_TYPES, checked=False | ||
| ) # type: DataAttribute[int] | ||
| last_index = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -407,3 +395,3 @@ Last removed value index. | ||
| stop = data_attribute(INTEGER_TYPES, checked=False) # type: DataAttribute[int] | ||
| stop = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -417,3 +405,3 @@ Stop index. | ||
| checked=False, | ||
| ) # type: DataAttribute[ListData[Any]] | ||
| ) # type: ListData[Any] | ||
| """ | ||
@@ -437,3 +425,3 @@ Old values. | ||
| STRING_TYPES, checked=False, default="Update values" | ||
| ) # type: DataAttribute[str] | ||
| ) # type: str | ||
| """ | ||
@@ -445,3 +433,3 @@ Name describing the change. | ||
| index = data_attribute(INTEGER_TYPES, checked=False) # type: DataAttribute[int] | ||
| index = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -453,5 +441,3 @@ First updated value index. | ||
| last_index = data_attribute( | ||
| INTEGER_TYPES, checked=False | ||
| ) # type: DataAttribute[int] | ||
| last_index = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -463,3 +449,3 @@ Last updated value index. | ||
| stop = data_attribute(INTEGER_TYPES, checked=False) # type: DataAttribute[int] | ||
| stop = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -473,3 +459,3 @@ Stop index. | ||
| checked=False, | ||
| ) # type: DataAttribute[ListData[Any]] | ||
| ) # type: ListData[Any] | ||
| """ | ||
@@ -483,3 +469,3 @@ Old values. | ||
| checked=False, | ||
| ) # type: DataAttribute[ListData[Any]] | ||
| ) # type: ListData[Any] | ||
| """ | ||
@@ -503,3 +489,3 @@ New values. | ||
| STRING_TYPES, checked=False, default="Move values" | ||
| ) # type: DataAttribute[str] | ||
| ) # type: str | ||
| """ | ||
@@ -511,3 +497,3 @@ Name describing the change. | ||
| index = data_attribute(INTEGER_TYPES, checked=False) # type: DataAttribute[int] | ||
| index = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -519,5 +505,3 @@ First moved value index. | ||
| last_index = data_attribute( | ||
| INTEGER_TYPES, checked=False | ||
| ) # type: DataAttribute[int] | ||
| last_index = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -529,3 +513,3 @@ Last moved value index. | ||
| stop = data_attribute(INTEGER_TYPES, checked=False) # type: DataAttribute[int] | ||
| stop = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -537,5 +521,3 @@ Stop index. | ||
| target_index = data_attribute( | ||
| INTEGER_TYPES, checked=False | ||
| ) # type: DataAttribute[int] | ||
| target_index = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -547,5 +529,3 @@ Index where values are being moved to. | ||
| post_index = data_attribute( | ||
| INTEGER_TYPES, checked=False | ||
| ) # type: DataAttribute[int] | ||
| post_index = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -557,5 +537,3 @@ First moved value index after the move. | ||
| post_last_index = data_attribute( | ||
| INTEGER_TYPES, checked=False | ||
| ) # type: DataAttribute[int] | ||
| post_last_index = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -567,3 +545,3 @@ Last moved value index after the move. | ||
| post_stop = data_attribute(INTEGER_TYPES, checked=False) # type: DataAttribute[int] | ||
| post_stop = data_attribute(INTEGER_TYPES, checked=False) # type: int | ||
| """ | ||
@@ -577,3 +555,3 @@ Stop index after the move. | ||
| checked=False, | ||
| ) # type: DataAttribute[ListData[Any]] | ||
| ) # type: ListData[Any] | ||
| """ | ||
@@ -597,3 +575,3 @@ Values being moved. | ||
| STRING_TYPES, checked=False, default="Add values" | ||
| ) # type: DataAttribute[str] | ||
| ) # type: str | ||
| """ | ||
@@ -605,5 +583,3 @@ Name describing the change. | ||
| new_values = data_protected_set_attribute( | ||
| checked=False | ||
| ) # type: DataAttribute[SetData[Any]] | ||
| new_values = data_protected_set_attribute(checked=False) # type: SetData[Any] | ||
| """ | ||
@@ -627,3 +603,3 @@ Values being added to the set. | ||
| STRING_TYPES, checked=False, default="Remove values" | ||
| ) # type: DataAttribute[str] | ||
| ) # type: str | ||
| """ | ||
@@ -635,5 +611,3 @@ Name describing the change. | ||
| old_values = data_protected_set_attribute( | ||
| checked=False | ||
| ) # type: DataAttribute[SetData[Any]] | ||
| old_values = data_protected_set_attribute(checked=False) # type: SetData[Any] | ||
| """ | ||
@@ -640,0 +614,0 @@ Values being removed from the set. |
@@ -23,2 +23,3 @@ # -*- coding: utf-8 -*- | ||
| ) | ||
| from ..utils.reraise_context import ReraiseContext | ||
| from ..utils.type_checking import assert_is_instance | ||
@@ -282,5 +283,9 @@ from .bases import BaseData, BaseDataMeta, BaseInteractiveData, DataRelationship | ||
| attribute = cls._get_attribute(name) | ||
| initial[name] = attribute.relationship.fabricate_value( | ||
| value, factory=factory | ||
| ) | ||
| with ReraiseContext( | ||
| Exception, | ||
| "initial attribute value for '{}.{}'".format(cls.__fullname__, name), | ||
| ): | ||
| initial[name] = attribute.relationship.fabricate_value( | ||
| value, factory=factory | ||
| ) | ||
@@ -292,3 +297,9 @@ missing_attributes = set() # type: Set[str] | ||
| if not missing_attributes: | ||
| initial[name] = attribute.fabricate_default_value() | ||
| with ReraiseContext( | ||
| Exception, | ||
| "initial attribute value for '{}.{}'".format( | ||
| cls.__fullname__, name | ||
| ), | ||
| ): | ||
| initial[name] = attribute.fabricate_default_value() | ||
| elif attribute.required: | ||
@@ -295,0 +306,0 @@ missing_attributes.add(name) |
+17
-18
@@ -20,3 +20,2 @@ # -*- coding: utf-8 -*- | ||
| from ._objects import ( | ||
| Attribute, | ||
| DictObject, | ||
@@ -37,11 +36,11 @@ ListObject, | ||
| MDA = Attribute[MutableDictObject[KT, VT]] | ||
| MLA = Attribute[MutableListObject[T]] | ||
| MSA = Attribute[MutableSetObject[T]] | ||
| DA = Attribute[DictObject[KT, VT]] | ||
| LA = Attribute[ListObject[T]] | ||
| SA = Attribute[SetObject[T]] | ||
| PDA = Attribute[ProxyDictObject[KT, VT]] | ||
| PLA = Attribute[ProxyListObject[T]] | ||
| PSA = Attribute[ProxySetObject[T]] | ||
| MDA = MutableDictObject[KT, VT] | ||
| MLA = MutableListObject[T] | ||
| MSA = MutableSetObject[T] | ||
| DA = DictObject[KT, VT] | ||
| LA = ListObject[T] | ||
| SA = SetObject[T] | ||
| PDA = ProxyDictObject[KT, VT] | ||
| PLA = ProxyListObject[T] | ||
| PSA = ProxySetObject[T] | ||
| CT = Union[BaseAtomicChange, "BatchChanges"] | ||
@@ -73,3 +72,3 @@ | ||
| change = attribute(Batch, checked=False, changeable=False) # type: Attribute[Batch] | ||
| change = attribute(Batch, checked=False, changeable=False) # type: Batch | ||
| """ | ||
@@ -81,3 +80,3 @@ Batch change with name and metadata. | ||
| name = attribute(str, checked=False, changeable=False) # type: Attribute[str] | ||
| name = attribute(str, checked=False, changeable=False) # type: str | ||
| """ | ||
@@ -101,3 +100,3 @@ The batch change name. | ||
| bool, checked=False, default=False | ||
| ) # type: Attribute[bool], Attribute[bool] | ||
| ) # type: bool, bool | ||
| """ | ||
@@ -168,3 +167,3 @@ Whether the batch has already completed or is still running. | ||
| changeable=False, | ||
| ) # type: Attribute[int] | ||
| ) # type: int | ||
| """ | ||
@@ -178,3 +177,3 @@ How many changes to remember. | ||
| bool, checked=False, default=False | ||
| ) # type: Attribute[bool], Attribute[bool] | ||
| ) # type: bool, bool | ||
| """ | ||
@@ -188,3 +187,3 @@ Whether the history is undoing or redoing. | ||
| bool, checked=False, default=False | ||
| ) # type: Attribute[bool], Attribute[bool] | ||
| ) # type: bool, bool | ||
| """ | ||
@@ -198,3 +197,3 @@ Whether the history is undoing. | ||
| bool, checked=False, default=False | ||
| ) # type: Attribute[bool], Attribute[bool] | ||
| ) # type: bool, bool | ||
| """ | ||
@@ -208,3 +207,3 @@ Whether the history is redoing. | ||
| int, checked=False, default=0 | ||
| ) # type: Attribute[int], Attribute[int] | ||
| ) # type: int, int | ||
| """ | ||
@@ -211,0 +210,0 @@ The index of the current change. |
@@ -15,3 +15,3 @@ # -*- coding: utf-8 -*- | ||
| from six import iteritems, itervalues, with_metaclass | ||
| from six import iteritems, itervalues, string_types, with_metaclass | ||
@@ -21,3 +21,3 @@ from .._applications import Application | ||
| from .._changes import Batch | ||
| from .._constants import BASE_STRING_TYPES, INTEGER_TYPES | ||
| from .._constants import INTEGER_TYPES | ||
| from .._data import BaseAuxiliaryData, BaseData, DataRelationship | ||
@@ -297,3 +297,3 @@ from .._states import BaseState, DictState | ||
| if issubclass(typ, BaseObject): | ||
| if isinstance(lazy, BASE_STRING_TYPES): | ||
| if isinstance(lazy, string_types): | ||
| types.add(lazy + ".Data") | ||
@@ -300,0 +300,0 @@ else: |
@@ -635,5 +635,11 @@ # -*- coding: utf-8 -*- | ||
| raise exc | ||
| initial[name] = attribute.relationship.fabricate_value( | ||
| value, factory=factory, **kwargs | ||
| ) | ||
| with ReraiseContext( | ||
| Exception, | ||
| "initial attribute value for '{}.{}'".format( | ||
| type(obj).__fullname__, name | ||
| ), | ||
| ): | ||
| initial[name] = attribute.relationship.fabricate_value( | ||
| value, factory=factory, **kwargs | ||
| ) | ||
@@ -643,3 +649,9 @@ for name, attribute in iteritems(cls._attributes): | ||
| if attribute.has_default: | ||
| initial[name] = attribute.fabricate_default_value(**kwargs) | ||
| with ReraiseContext( | ||
| Exception, | ||
| "initial attribute value for '{}.{}'".format( | ||
| type(obj).__fullname__, name | ||
| ), | ||
| ): | ||
| initial[name] = attribute.fabricate_default_value(**kwargs) | ||
@@ -646,0 +658,0 @@ return initial |
@@ -20,3 +20,2 @@ # -*- coding: utf-8 -*- | ||
| from .data import DataAttribute | ||
@@ -224,5 +223,3 @@ __all__ = ["ActionObserver", "ActionObserverToken", "ActionObserverExceptionData"] | ||
| observer = data_attribute( | ||
| ActionObserver, checked=False | ||
| ) # type: DataAttribute[ActionObserver] | ||
| observer = data_attribute(ActionObserver, checked=False) # type: ActionObserver | ||
| """ | ||
@@ -234,3 +231,3 @@ Action observer. | ||
| action = data_attribute(Action, checked=False) # type: DataAttribute[Action] | ||
| action = data_attribute(Action, checked=False) # type: Action | ||
| """ | ||
@@ -242,3 +239,3 @@ Action. | ||
| phase = data_attribute(Phase, checked=False) # type: DataAttribute[Phase] | ||
| phase = data_attribute(Phase, checked=False) # type: Phase | ||
| """ | ||
@@ -252,3 +249,3 @@ Phase. | ||
| (type(BaseException), None), checked=False | ||
| ) # type: DataAttribute[Optional[Type[BaseException]]] | ||
| ) # type: Optional[Type[BaseException]] | ||
| """ | ||
@@ -262,3 +259,3 @@ Exception type. | ||
| (BaseException, None), checked=False | ||
| ) # type: DataAttribute[Optional[BaseException]] | ||
| ) # type: Optional[BaseException] | ||
| """ | ||
@@ -272,3 +269,3 @@ Exception. | ||
| (TracebackType, None), checked=False | ||
| ) # type: DataAttribute[Optional[TracebackType]] | ||
| ) # type: Optional[TracebackType] | ||
| """ | ||
@@ -275,0 +272,0 @@ Traceback. |
@@ -45,3 +45,2 @@ # -*- coding: utf-8 -*- | ||
| # noinspection PyAbstractClass | ||
| def reaction( | ||
@@ -48,0 +47,0 @@ func=None, # type: Optional[Callable[[_BO, Action, Phase], None]] |
@@ -616,3 +616,2 @@ # -*- coding: utf-8 -*- | ||
| # noinspection PyAbstractClass | ||
| def unique_descriptor(): | ||
@@ -619,0 +618,0 @@ # type: () -> UniqueDescriptor |
@@ -616,7 +616,7 @@ # -*- coding: utf-8 -*- | ||
| ) | ||
| except TypeError: | ||
| except TypeError as e: | ||
| error = ( | ||
| "attribute {} '{}.{}' value type '{}' is not " | ||
| "compatible with {} '{}.{}' constant attribute " | ||
| "type '{}'" | ||
| "type '{}': {}" | ||
| ).format( | ||
@@ -631,2 +631,3 @@ member_label, | ||
| type(abstract_attribute.default).__name__, | ||
| e, | ||
| ) | ||
@@ -768,2 +769,3 @@ exc = TypeError(error) | ||
| # Match! | ||
| assert not isinstance(typ, str) | ||
| if issubclass(t, typ): | ||
@@ -770,0 +772,0 @@ break |
+279
-297
| # -*- coding: utf-8 -*- | ||
| """Data.""" | ||
| from typing import TYPE_CHECKING, TypeVar | ||
| from ._bases import MISSING | ||
@@ -33,7 +31,2 @@ from ._data import ( | ||
| if TYPE_CHECKING: | ||
| from typing import Any, Dict, Iterable, Optional, Type, Union | ||
| from .utils.factoring import LazyFactory | ||
| __all__ = [ | ||
@@ -69,41 +62,28 @@ "DataRelationship", | ||
| "data_set_cls", | ||
| "data_protected_dict_cls", | ||
| "data_protected_list_cls", | ||
| "data_protected_set_cls", | ||
| ] | ||
| T = TypeVar("T") # Any type. | ||
| KT = TypeVar("KT") # Any key type. | ||
| VT = TypeVar("VT") # Any value type. | ||
| if TYPE_CHECKING: | ||
| NT = Union[Type[None], None] | ||
| InteractiveDictAttribute = DataAttribute[InteractiveDictData[KT, VT]] | ||
| InteractiveListAttribute = DataAttribute[InteractiveListData[T]] | ||
| InteractiveSetAttribute = DataAttribute[InteractiveSetData[T]] | ||
| DictAttribute = DataAttribute[DictData[KT, VT]] | ||
| ListAttribute = DataAttribute[ListData[T]] | ||
| SetAttribute = DataAttribute[SetData[T]] | ||
| def data_attribute( | ||
| types=(), # type: Union[Type[T], NT, str, Iterable[Union[Type[T], NT, str]]] | ||
| subtypes=False, # type: bool | ||
| checked=None, # type: Optional[bool] | ||
| module=None, # type: Optional[str] | ||
| factory=None, # type: LazyFactory | ||
| serialized=True, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=True, # type: bool | ||
| compared=True, # type: bool | ||
| default=MISSING, # type: Any | ||
| default_factory=None, # type: LazyFactory | ||
| required=True, # type: bool | ||
| changeable=True, # type: bool | ||
| deletable=False, # type: bool | ||
| finalized=False, # type: bool | ||
| abstracted=False, # type: bool | ||
| metadata=None, # type: Any | ||
| types=(), | ||
| subtypes=False, | ||
| checked=None, | ||
| module=None, | ||
| factory=None, | ||
| serialized=True, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=True, | ||
| compared=True, | ||
| default=MISSING, | ||
| default_factory=None, | ||
| required=True, | ||
| changeable=True, | ||
| deletable=False, | ||
| finalized=False, | ||
| abstracted=False, | ||
| metadata=None, | ||
| ): | ||
| # type: (...) -> DataAttribute[T] | ||
| """ | ||
@@ -202,3 +182,3 @@ Make data attribute. | ||
| metadata=metadata, | ||
| ) # type: DataAttribute[T] | ||
| ) | ||
@@ -209,14 +189,15 @@ return attribute | ||
| def data_constant_attribute( | ||
| value, # type: T | ||
| checked=True, # type: bool | ||
| serialized=False, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=False, # type: bool | ||
| compared=True, # type: bool | ||
| finalized=False, # type: bool | ||
| abstracted=False, # type: bool | ||
| metadata=None, # type: Any | ||
| value, | ||
| subtypes=False, | ||
| checked=True, | ||
| serialized=False, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=False, | ||
| compared=True, | ||
| finalized=False, | ||
| abstracted=False, | ||
| metadata=None, | ||
| ): | ||
| # type: (...) -> DataAttribute[T] | ||
| """ | ||
@@ -227,2 +208,5 @@ Make constant data attribute. | ||
| :param subtypes: Whether to accept subtypes. | ||
| :type subtypes: bool | ||
| :param checked: Whether to type check when overriding this constant attribute. | ||
@@ -265,3 +249,3 @@ :type checked: bool | ||
| types=type(value), | ||
| subtypes=False, | ||
| subtypes=subtypes, | ||
| checked=checked, | ||
@@ -287,3 +271,3 @@ serialized=serialized, | ||
| metadata=metadata, | ||
| ) # type: DataAttribute[T] | ||
| ) | ||
@@ -294,27 +278,27 @@ return attribute_ | ||
| def data_dict_attribute( | ||
| types=(), # type: Union[Type[VT], NT, str, Iterable[Union[Type[VT], NT, str]]] | ||
| subtypes=False, # type: bool | ||
| checked=None, # type: Optional[bool] | ||
| module=None, # type: Optional[str] | ||
| factory=None, # type: LazyFactory | ||
| serialized=True, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=True, # type: bool | ||
| compared=True, # type: bool | ||
| key_types=(), # type: Union[Type[KT], NT, str, Iterable[Union[Type[KT], NT, str]]] | ||
| key_subtypes=False, # type: bool | ||
| key_factory=None, # type: LazyFactory | ||
| default=MISSING, # type: Any | ||
| default_factory=None, # type: LazyFactory | ||
| required=False, # type: bool | ||
| changeable=True, # type: bool | ||
| deletable=False, # type: bool | ||
| finalized=False, # type: bool | ||
| abstracted=False, # type: bool | ||
| metadata=None, # type: Any | ||
| qual_name=None, # type: Optional[str] | ||
| unique=False, # type: bool | ||
| types=(), | ||
| subtypes=False, | ||
| checked=None, | ||
| module=None, | ||
| factory=None, | ||
| serialized=True, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=True, | ||
| compared=True, | ||
| key_types=(), | ||
| key_subtypes=False, | ||
| key_factory=None, | ||
| default=MISSING, | ||
| default_factory=None, | ||
| required=False, | ||
| changeable=True, | ||
| deletable=False, | ||
| finalized=False, | ||
| abstracted=False, | ||
| metadata=None, | ||
| qual_name=None, | ||
| unique=False, | ||
| ): | ||
| # type: (...) -> InteractiveDictAttribute[KT, VT] | ||
| """ | ||
@@ -418,3 +402,3 @@ Make interactive dictionary data attribute. | ||
| unique=unique, | ||
| ) # type: Type[InteractiveDictData[KT, VT]] | ||
| ) | ||
@@ -460,3 +444,3 @@ # Factory that forces the dictionary type. | ||
| metadata=metadata, | ||
| ) # type: DataAttribute[InteractiveDictData[KT, VT]] | ||
| ) | ||
@@ -467,27 +451,27 @@ return attribute_ | ||
| def data_protected_dict_attribute( | ||
| types=(), # type: Union[Type[VT], NT, str, Iterable[Union[Type[VT], NT, str]]] | ||
| subtypes=False, # type: bool | ||
| checked=None, # type: Optional[bool] | ||
| module=None, # type: Optional[str] | ||
| factory=None, # type: LazyFactory | ||
| serialized=True, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=True, # type: bool | ||
| compared=True, # type: bool | ||
| key_types=(), # type: Union[Type[KT], NT, str, Iterable[Union[Type[KT], NT, str]]] | ||
| key_subtypes=False, # type: bool | ||
| key_factory=None, # type: LazyFactory | ||
| default=MISSING, # type: Any | ||
| default_factory=None, # type: LazyFactory | ||
| required=False, # type: bool | ||
| changeable=True, # type: bool | ||
| deletable=False, # type: bool | ||
| finalized=False, # type: bool | ||
| abstracted=False, # type: bool | ||
| metadata=None, # type: Any | ||
| qual_name=None, # type: Optional[str] | ||
| unique=False, # type: bool | ||
| types=(), | ||
| subtypes=False, | ||
| checked=None, | ||
| module=None, | ||
| factory=None, | ||
| serialized=True, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=True, | ||
| compared=True, | ||
| key_types=(), | ||
| key_subtypes=False, | ||
| key_factory=None, | ||
| default=MISSING, | ||
| default_factory=None, | ||
| required=False, | ||
| changeable=True, | ||
| deletable=False, | ||
| finalized=False, | ||
| abstracted=False, | ||
| metadata=None, | ||
| qual_name=None, | ||
| unique=False, | ||
| ): | ||
| # type: (...) -> DictAttribute[KT, VT] | ||
| """ | ||
@@ -593,3 +577,3 @@ Make protected dictionary data attribute. | ||
| unique=unique, | ||
| ) # type: Type[DictData[KT, VT]] | ||
| ) | ||
@@ -639,3 +623,3 @@ # Factory that forces the dictionary type. | ||
| metadata=metadata, | ||
| ) # type: DataAttribute[DictData[KT, VT]] | ||
| ) | ||
@@ -646,24 +630,24 @@ return attribute_ | ||
| def data_list_attribute( | ||
| types=(), # type: Union[Type[T], NT, str, Iterable[Union[Type[T], NT, str]]] | ||
| subtypes=False, # type: bool | ||
| checked=None, # type: Optional[bool] | ||
| module=None, # type: Optional[str] | ||
| factory=None, # type: LazyFactory | ||
| serialized=True, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=True, # type: bool | ||
| compared=True, # type: bool | ||
| default=MISSING, # type: Any | ||
| default_factory=None, # type: LazyFactory | ||
| required=False, # type: bool | ||
| changeable=True, # type: bool | ||
| deletable=False, # type: bool | ||
| finalized=False, # type: bool | ||
| abstracted=False, # type: bool | ||
| metadata=None, # type: Any | ||
| qual_name=None, # type: Optional[str] | ||
| unique=False, # type: bool | ||
| types=(), | ||
| subtypes=False, | ||
| checked=None, | ||
| module=None, | ||
| factory=None, | ||
| serialized=True, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=True, | ||
| compared=True, | ||
| default=MISSING, | ||
| default_factory=None, | ||
| required=False, | ||
| changeable=True, | ||
| deletable=False, | ||
| finalized=False, | ||
| abstracted=False, | ||
| metadata=None, | ||
| qual_name=None, | ||
| unique=False, | ||
| ): | ||
| # type: (...) -> InteractiveListAttribute[T] | ||
| """ | ||
@@ -755,3 +739,3 @@ Make interactive list data attribute. | ||
| unique=unique, | ||
| ) # type: Type[InteractiveListData[T]] | ||
| ) | ||
@@ -797,3 +781,3 @@ # Factory that forces the list type. | ||
| metadata=metadata, | ||
| ) # type: DataAttribute[InteractiveListData[T]] | ||
| ) | ||
@@ -804,24 +788,24 @@ return attribute_ | ||
| def data_protected_list_attribute( | ||
| types=(), # type: Union[Type[T], NT, str, Iterable[Union[Type[T], NT, str]]] | ||
| subtypes=False, # type: bool | ||
| checked=None, # type: Optional[bool] | ||
| module=None, # type: Optional[str] | ||
| factory=None, # type: LazyFactory | ||
| serialized=True, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=True, # type: bool | ||
| compared=True, # type: bool | ||
| default=MISSING, # type: Any | ||
| default_factory=None, # type: LazyFactory | ||
| required=False, # type: bool | ||
| changeable=True, # type: bool | ||
| deletable=False, # type: bool | ||
| finalized=False, # type: bool | ||
| abstracted=False, # type: bool | ||
| metadata=None, # type: Any | ||
| qual_name=None, # type: Optional[str] | ||
| unique=False, # type: bool | ||
| types=(), | ||
| subtypes=False, | ||
| checked=None, | ||
| module=None, | ||
| factory=None, | ||
| serialized=True, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=True, | ||
| compared=True, | ||
| default=MISSING, | ||
| default_factory=None, | ||
| required=False, | ||
| changeable=True, | ||
| deletable=False, | ||
| finalized=False, | ||
| abstracted=False, | ||
| metadata=None, | ||
| qual_name=None, | ||
| unique=False, | ||
| ): | ||
| # type: (...) -> ListAttribute[T] | ||
| """ | ||
@@ -915,3 +899,3 @@ Make protected list data attribute. | ||
| unique=unique, | ||
| ) # type: Type[ListData[T]] | ||
| ) | ||
@@ -961,3 +945,3 @@ # Factory that forces the list type. | ||
| metadata=metadata, | ||
| ) # type: DataAttribute[ListData[T]] | ||
| ) | ||
@@ -968,24 +952,24 @@ return attribute_ | ||
| def data_set_attribute( | ||
| types=(), # type: Union[Type[T], NT, str, Iterable[Union[Type[T], NT, str]]] | ||
| subtypes=False, # type: bool | ||
| checked=None, # type: Optional[bool] | ||
| module=None, # type: Optional[str] | ||
| factory=None, # type: LazyFactory | ||
| serialized=True, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=True, # type: bool | ||
| compared=True, # type: bool | ||
| default=MISSING, # type: Any | ||
| default_factory=None, # type: LazyFactory | ||
| required=False, # type: bool | ||
| changeable=True, # type: bool | ||
| deletable=False, # type: bool | ||
| finalized=False, # type: bool | ||
| abstracted=False, # type: bool | ||
| metadata=None, # type: Any | ||
| qual_name=None, # type: Optional[str] | ||
| unique=False, # type: bool | ||
| types=(), | ||
| subtypes=False, | ||
| checked=None, | ||
| module=None, | ||
| factory=None, | ||
| serialized=True, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=True, | ||
| compared=True, | ||
| default=MISSING, | ||
| default_factory=None, | ||
| required=False, | ||
| changeable=True, | ||
| deletable=False, | ||
| finalized=False, | ||
| abstracted=False, | ||
| metadata=None, | ||
| qual_name=None, | ||
| unique=False, | ||
| ): | ||
| # type: (...) -> InteractiveSetAttribute[T] | ||
| """ | ||
@@ -1077,3 +1061,3 @@ Make interactive set data attribute. | ||
| unique=unique, | ||
| ) # type: Type[InteractiveSetData[T]] | ||
| ) | ||
@@ -1119,3 +1103,3 @@ # Factory that forces the set type. | ||
| metadata=metadata, | ||
| ) # type: DataAttribute[InteractiveSetData[T]] | ||
| ) | ||
@@ -1126,24 +1110,24 @@ return attribute_ | ||
| def data_protected_set_attribute( | ||
| types=(), # type: Union[Type[T], NT, str, Iterable[Union[Type[T], NT, str]]] | ||
| subtypes=False, # type: bool | ||
| checked=None, # type: Optional[bool] | ||
| module=None, # type: Optional[str] | ||
| factory=None, # type: LazyFactory | ||
| serialized=True, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=True, # type: bool | ||
| compared=True, # type: bool | ||
| default=MISSING, # type: Any | ||
| default_factory=None, # type: LazyFactory | ||
| required=False, # type: bool | ||
| changeable=True, # type: bool | ||
| deletable=False, # type: bool | ||
| finalized=False, # type: bool | ||
| abstracted=False, # type: bool | ||
| metadata=None, # type: Any | ||
| qual_name=None, # type: Optional[str] | ||
| unique=False, # type: bool | ||
| types=(), | ||
| subtypes=False, | ||
| checked=None, | ||
| module=None, | ||
| factory=None, | ||
| serialized=True, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=True, | ||
| compared=True, | ||
| default=MISSING, | ||
| default_factory=None, | ||
| required=False, | ||
| changeable=True, | ||
| deletable=False, | ||
| finalized=False, | ||
| abstracted=False, | ||
| metadata=None, | ||
| qual_name=None, | ||
| unique=False, | ||
| ): | ||
| # type: (...) -> SetAttribute[T] | ||
| """ | ||
@@ -1237,3 +1221,3 @@ Make protected set data attribute. | ||
| unique=unique, | ||
| ) # type: Type[SetData[T]] | ||
| ) | ||
@@ -1283,3 +1267,3 @@ # Factory that forces the set type. | ||
| metadata=metadata, | ||
| ) # type: DataAttribute[SetData[T]] | ||
| ) | ||
@@ -1290,19 +1274,19 @@ return attribute_ | ||
| def data_dict_cls( | ||
| types=(), # type: Union[Type[VT], NT, str, Iterable[Union[Type[VT], NT, str]]] | ||
| subtypes=False, # type: bool | ||
| checked=None, # type: Optional[bool] | ||
| module=None, # type: Optional[str] | ||
| factory=None, # type: LazyFactory | ||
| serialized=True, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=True, # type: bool | ||
| compared=True, # type: bool | ||
| key_types=(), # type: Union[Type[KT], NT, str, Iterable[Union[Type[KT], NT, str]]] | ||
| key_subtypes=False, # type: bool | ||
| key_factory=None, # type: LazyFactory | ||
| qual_name=None, # type: Optional[str] | ||
| unique=False, # type: bool | ||
| types=(), | ||
| subtypes=False, | ||
| checked=None, | ||
| module=None, | ||
| factory=None, | ||
| serialized=True, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=True, | ||
| compared=True, | ||
| key_types=(), | ||
| key_subtypes=False, | ||
| key_factory=None, | ||
| qual_name=None, | ||
| unique=False, | ||
| ): | ||
| # type: (...) -> Type[InteractiveDictData[KT, VT]] | ||
| """ | ||
@@ -1399,7 +1383,5 @@ Make auxiliary interactive dictionary data class. | ||
| dct=dct, | ||
| ) # type: Dict[str, Any] | ||
| ) | ||
| with ReraiseContext(TypeError, "defining 'data_dict_cls'"): | ||
| interactive_base = ( | ||
| InteractiveDictData | ||
| ) # type: Type[InteractiveDictData[KT, VT]] | ||
| interactive_base = InteractiveDictData | ||
| return make_auxiliary_cls(interactive_base, **cls_kwargs) | ||
@@ -1409,19 +1391,19 @@ | ||
| def data_protected_dict_cls( | ||
| types=(), # type: Union[Type[VT], NT, str, Iterable[Union[Type[VT], NT, str]]] | ||
| subtypes=False, # type: bool | ||
| checked=None, # type: Optional[bool] | ||
| module=None, # type: Optional[str] | ||
| factory=None, # type: LazyFactory | ||
| serialized=True, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=True, # type: bool | ||
| compared=True, # type: bool | ||
| key_types=(), # type: Union[Type[KT], NT, str, Iterable[Union[Type[KT], NT, str]]] | ||
| key_subtypes=False, # type: bool | ||
| key_factory=None, # type: LazyFactory | ||
| qual_name=None, # type: Optional[str] | ||
| unique=False, # type: bool | ||
| types=(), | ||
| subtypes=False, | ||
| checked=None, | ||
| module=None, | ||
| factory=None, | ||
| serialized=True, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=True, | ||
| compared=True, | ||
| key_types=(), | ||
| key_subtypes=False, | ||
| key_factory=None, | ||
| qual_name=None, | ||
| unique=False, | ||
| ): | ||
| # type: (...) -> Type[DictData[KT, VT]] | ||
| """ | ||
@@ -1518,5 +1500,5 @@ Make auxiliary protected dictionary data class. | ||
| dct=dct, | ||
| ) # type: Dict[str, Any] | ||
| ) | ||
| with ReraiseContext(TypeError, "defining 'data_protected_dict_cls'"): | ||
| base = DictData # type: Type[DictData[KT, VT]] | ||
| base = DictData | ||
| return make_auxiliary_cls(base, **cls_kwargs) | ||
@@ -1526,16 +1508,16 @@ | ||
| def data_list_cls( | ||
| types=(), # type: Union[Type[T], NT, str, Iterable[Union[Type[T], NT, str]]] | ||
| subtypes=False, # type: bool | ||
| checked=None, # type: Optional[bool] | ||
| module=None, # type: Optional[str] | ||
| factory=None, # type: LazyFactory | ||
| serialized=True, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=True, # type: bool | ||
| compared=True, # type: bool | ||
| qual_name=None, # type: Optional[str] | ||
| unique=False, # type: bool | ||
| types=(), | ||
| subtypes=False, | ||
| checked=None, | ||
| module=None, | ||
| factory=None, | ||
| serialized=True, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=True, | ||
| compared=True, | ||
| qual_name=None, | ||
| unique=False, | ||
| ): | ||
| # type: (...) -> Type[InteractiveListData[T]] | ||
| """ | ||
@@ -1611,5 +1593,5 @@ Make auxiliary interactive list data class. | ||
| unique_descriptor_name="unique_hash" if unique else None, | ||
| ) # type: Dict[str, Any] | ||
| ) | ||
| with ReraiseContext(TypeError, "defining 'data_list_cls'"): | ||
| interactive_base = InteractiveListData # type: Type[InteractiveListData[T]] | ||
| interactive_base = InteractiveListData | ||
| return make_auxiliary_cls(interactive_base, **cls_kwargs) | ||
@@ -1619,16 +1601,16 @@ | ||
| def data_protected_list_cls( | ||
| types=(), # type: Union[Type[T], NT, str, Iterable[Union[Type[T], NT, str]]] | ||
| subtypes=False, # type: bool | ||
| checked=None, # type: Optional[bool] | ||
| module=None, # type: Optional[str] | ||
| factory=None, # type: LazyFactory | ||
| serialized=True, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=True, # type: bool | ||
| compared=True, # type: bool | ||
| qual_name=None, # type: Optional[str] | ||
| unique=False, # type: bool | ||
| types=(), | ||
| subtypes=False, | ||
| checked=None, | ||
| module=None, | ||
| factory=None, | ||
| serialized=True, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=True, | ||
| compared=True, | ||
| qual_name=None, | ||
| unique=False, | ||
| ): | ||
| # type: (...) -> Type[ListData[T]] | ||
| """ | ||
@@ -1704,5 +1686,5 @@ Make auxiliary protected list data class. | ||
| unique_descriptor_name="unique_hash" if unique else None, | ||
| ) # type: Dict[str, Any] | ||
| ) | ||
| with ReraiseContext(TypeError, "defining 'data_protected_list_cls'"): | ||
| base = ListData # type: Type[ListData[T]] | ||
| base = ListData | ||
| return make_auxiliary_cls(base, **cls_kwargs) | ||
@@ -1712,16 +1694,16 @@ | ||
| def data_set_cls( | ||
| types=(), # type: Union[Type[T], NT, str, Iterable[Union[Type[T], NT, str]]] | ||
| subtypes=False, # type: bool | ||
| checked=None, # type: Optional[bool] | ||
| module=None, # type: Optional[str] | ||
| factory=None, # type: LazyFactory | ||
| serialized=True, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=True, # type: bool | ||
| compared=True, # type: bool | ||
| qual_name=None, # type: Optional[str] | ||
| unique=False, # type: bool | ||
| types=(), | ||
| subtypes=False, | ||
| checked=None, | ||
| module=None, | ||
| factory=None, | ||
| serialized=True, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=True, | ||
| compared=True, | ||
| qual_name=None, | ||
| unique=False, | ||
| ): | ||
| # type: (...) -> Type[InteractiveSetData[T]] | ||
| """ | ||
@@ -1797,5 +1779,5 @@ Make auxiliary interactive set data class. | ||
| unique_descriptor_name="unique_hash" if unique else None, | ||
| ) # type: Dict[str, Any] | ||
| ) | ||
| with ReraiseContext(TypeError, "defining 'data_set_cls'"): | ||
| interactive_base = InteractiveSetData # type: Type[InteractiveSetData[T]] | ||
| interactive_base = InteractiveSetData | ||
| return make_auxiliary_cls(interactive_base, **cls_kwargs) | ||
@@ -1805,16 +1787,16 @@ | ||
| def data_protected_set_cls( | ||
| types=(), # type: Union[Type[T], NT, str, Iterable[Union[Type[T], NT, str]]] | ||
| subtypes=False, # type: bool | ||
| checked=None, # type: Optional[bool] | ||
| module=None, # type: Optional[str] | ||
| factory=None, # type: LazyFactory | ||
| serialized=True, # type: bool | ||
| serializer=None, # type: LazyFactory | ||
| deserializer=None, # type: LazyFactory | ||
| represented=True, # type: bool | ||
| compared=True, # type: bool | ||
| qual_name=None, # type: Optional[str] | ||
| unique=False, # type: bool | ||
| types=(), | ||
| subtypes=False, | ||
| checked=None, | ||
| module=None, | ||
| factory=None, | ||
| serialized=True, | ||
| serializer=None, | ||
| deserializer=None, | ||
| represented=True, | ||
| compared=True, | ||
| qual_name=None, | ||
| unique=False, | ||
| ): | ||
| # type: (...) -> Type[SetData[T]] | ||
| """ | ||
@@ -1890,5 +1872,5 @@ Make auxiliary protected set data class. | ||
| unique_descriptor_name="unique_hash" if unique else None, | ||
| ) # type: Dict[str, Any] | ||
| ) | ||
| with ReraiseContext(TypeError, "defining 'data_protected_set_cls'"): | ||
| base = SetData # type: Type[SetData[T]] | ||
| base = SetData | ||
| return make_auxiliary_cls(base, **cls_kwargs) |
@@ -51,2 +51,3 @@ # -*- coding: utf-8 -*- | ||
| else: | ||
| assert not isinstance(factory, str) | ||
| return factory.__name__ | ||
@@ -53,0 +54,0 @@ |
@@ -7,3 +7,3 @@ # -*- coding: utf-8 -*- | ||
| from qualname import qualname # type: ignore | ||
| from .qualname import qualname | ||
@@ -10,0 +10,0 @@ if TYPE_CHECKING: |
@@ -5,2 +5,3 @@ # -*- coding: utf-8 -*- | ||
| from collections import Counter as ValueCounter | ||
| from functools import wraps | ||
| from threading import local | ||
@@ -14,8 +15,12 @@ from typing import TYPE_CHECKING | ||
| from decorator import decorator | ||
| from qualname import qualname # type: ignore | ||
| from six import raise_from | ||
| from .qualname import qualname | ||
| from .simplify_exceptions import simplify_exceptions | ||
| if TYPE_CHECKING: | ||
| from typing import Any, Callable, Optional | ||
| from typing import Callable, Optional, TypeVar | ||
| RT = TypeVar("RT") # return type | ||
| __all__ = ["recursive_repr"] | ||
@@ -26,11 +31,4 @@ | ||
| @decorator | ||
| def recursive_repr( | ||
| func, # type: Callable | ||
| max_depth=1, # type: Optional[int] | ||
| max_global_depth=2, # type: Optional[int] | ||
| *args, # type: Any | ||
| **kwargs # type: Any | ||
| ): | ||
| # type: (...) -> str | ||
| def recursive_repr(func): | ||
| # type: (Callable[..., RT]) -> Callable[..., RT] | ||
| """ | ||
@@ -56,43 +54,51 @@ Decorate a representation method/function and prevents infinite recursion. | ||
| :param max_depth: Maximum recursion depth before returning fill value. | ||
| :type max_depth: int | ||
| :param max_global_depth: Maximum global depth before returning fill value. | ||
| :type max_global_depth: int | ||
| :return: Decorated method function. | ||
| :rtype: function | ||
| """ | ||
| self = args[0] | ||
| self_id = id(self) | ||
| try: | ||
| reprs = _local.reprs | ||
| except AttributeError: | ||
| reprs = _local.reprs = ValueCounter() | ||
| try: | ||
| global_reprs = _local.global_reprs | ||
| except AttributeError: | ||
| global_reprs = _local.global_reprs = [0] | ||
| max_depth = 1 # type: Optional[int] | ||
| max_global_depth = 2 # type: Optional[int] | ||
| reprs[self_id] += 1 | ||
| global_reprs[0] += 1 | ||
| try: | ||
| if max_depth is not None and reprs[self_id] > max_depth: | ||
| return "..." | ||
| elif max_global_depth is not None and global_reprs[0] > max_global_depth: | ||
| try: | ||
| qual_name = qualname(type(self)) | ||
| except AttributeError: | ||
| qual_name = type(self).__name__ | ||
| return "<{} at {}>".format(qual_name, hex(id(self))) | ||
| else: | ||
| return func(*args, **kwargs) | ||
| finally: | ||
| reprs[self_id] -= 1 | ||
| if not reprs[self_id]: | ||
| del reprs[self_id] | ||
| if not reprs: | ||
| del _local.reprs | ||
| global_reprs[0] -= 1 | ||
| if not global_reprs[0]: | ||
| del _local.global_reprs | ||
| @wraps(func) | ||
| @simplify_exceptions | ||
| def decorated(*args, **kwargs): | ||
| try: | ||
| self = args[0] | ||
| except IndexError: | ||
| exc = RuntimeError("'recursive_repr' needs to be used on a instance method") | ||
| raise_from(exc, None) | ||
| raise exc | ||
| self_id = id(self) | ||
| try: | ||
| reprs = _local.reprs | ||
| except AttributeError: | ||
| reprs = _local.reprs = ValueCounter() | ||
| try: | ||
| global_reprs = _local.global_reprs | ||
| except AttributeError: | ||
| global_reprs = _local.global_reprs = [0] | ||
| reprs[self_id] += 1 | ||
| global_reprs[0] += 1 | ||
| try: | ||
| if max_depth is not None and reprs[self_id] > max_depth: | ||
| return "..." | ||
| elif max_global_depth is not None and global_reprs[0] > max_global_depth: | ||
| try: | ||
| qual_name = qualname(type(self)) | ||
| except AttributeError: | ||
| qual_name = type(self).__name__ | ||
| return "<{} at {}>".format(qual_name, hex(id(self))) | ||
| else: | ||
| return func(*args, **kwargs) | ||
| finally: | ||
| reprs[self_id] -= 1 | ||
| if not reprs[self_id]: | ||
| del reprs[self_id] | ||
| if not reprs: | ||
| del _local.reprs | ||
| global_reprs[0] -= 1 | ||
| if not global_reprs[0]: | ||
| del _local.global_reprs | ||
| return decorated |
@@ -14,2 +14,3 @@ # -*- coding: utf-8 -*- | ||
| from .._constants import INTEGER_TYPES, STRING_TYPES | ||
| from ..utils.lazy_import import decorate_path, import_path | ||
@@ -154,4 +155,2 @@ | ||
| ('chain', 'compress') | ||
| >>> get_type_names(import_types(("itertools|chain", int))) | ||
| ('chain', 'int') | ||
@@ -164,6 +163,15 @@ :param types: Types. | ||
| """ | ||
| return tuple( | ||
| cast(type, import_path(t)) if isinstance(t, string_types) else t | ||
| imported_types = tuple( | ||
| cast("Type", import_path(t)) if isinstance(t, string_types) else cast("Type", t) | ||
| for t in flatten_types(types) | ||
| ) | ||
| if len(STRING_TYPES) > 1: | ||
| all_string_types = set(STRING_TYPES) | ||
| if all_string_types.intersection(imported_types): | ||
| imported_types += tuple(all_string_types.difference(imported_types)) | ||
| if len(INTEGER_TYPES) > 1: | ||
| all_integer_types = set(INTEGER_TYPES) | ||
| if all_integer_types.intersection(imported_types): | ||
| imported_types += tuple(all_integer_types.difference(imported_types)) | ||
| return imported_types | ||
@@ -170,0 +178,0 @@ |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: objetto | ||
| Version: 1.28.0 | ||
| Version: 1.29.0 | ||
| Summary: Object-oriented framework for building smart applications and APIs | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/brunonicko/objetto |
+1
-3
@@ -8,3 +8,3 @@ import setuptools | ||
| name="objetto", | ||
| version="1.28.0", | ||
| version="1.29.0", | ||
| author="Bruno Nicko", | ||
@@ -20,5 +20,3 @@ author_email="brunonicko@gmail.com", | ||
| "enum34; python_version < '3.4'", | ||
| "decorator", | ||
| "pyrsistent", | ||
| "qualname", | ||
| "six", | ||
@@ -25,0 +23,0 @@ "slotted", |
Sorry, the diff of this file is too big to display
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
100
4.17%25655
0.54%1017318
-1.17%