1from functools import wraps
2
3from sqlalchemy.orm.collections import InstrumentedList as _InstrumentedList
4
5from .arrow import ArrowType # noqa
6from .choice import Choice, ChoiceType # noqa
7from .color import ColorType # noqa
8from .country import CountryType # noqa
9from .currency import CurrencyType # noqa
10from .email import EmailType # noqa
11from .encrypted.encrypted_type import ( # noqa
12 EncryptedType,
13 StringEncryptedType,
14)
15from .enriched_datetime.enriched_date_type import EnrichedDateType # noqa
16from .ip_address import IPAddressType # noqa
17from .json import JSONType # noqa
18from .locale import LocaleType # noqa
19from .ltree import LtreeType # noqa
20from .password import Password, PasswordType # noqa
21from .pg_composite import ( # noqa
22 CompositeType,
23 register_composites,
24 remove_composite_listeners,
25)
26from .phone_number import ( # noqa
27 PhoneNumber,
28 PhoneNumberParseException,
29 PhoneNumberType,
30)
31from .range import ( # noqa
32 DateRangeType,
33 DateTimeRangeType,
34 Int8RangeType,
35 IntRangeType,
36 NumericRangeType,
37)
38from .scalar_list import ScalarListException, ScalarListType # noqa
39from .timezone import TimezoneType # noqa
40from .ts_vector import TSVectorType # noqa
41from .url import URLType # noqa
42from .uuid import UUIDType # noqa
43from .weekdays import WeekDaysType # noqa
44
45from .enriched_datetime.enriched_datetime_type import EnrichedDateTimeType # noqa isort:skip
46
47
48class InstrumentedList(_InstrumentedList):
49 """Enhanced version of SQLAlchemy InstrumentedList. Provides some
50 additional functionality."""
51
52 def any(self, attr):
53 return any(getattr(item, attr) for item in self)
54
55 def all(self, attr):
56 return all(getattr(item, attr) for item in self)
57
58
59def instrumented_list(f):
60 @wraps(f)
61 def wrapper(*args, **kwargs):
62 return InstrumentedList([item for item in f(*args, **kwargs)])
63
64 return wrapper