Represent a PostgreSQL range. E.g.:: r = Range(10, 50, bounds="()") The calling style is similar to that of psycopg and psycopg2, in part to allow easier migration from previous SQLAlchemy versions that used these objects directly. :param lower: Lower bound value, or
| 51 | |
| 52 | @dataclasses.dataclass(frozen=True, slots=True) |
| 53 | class Range(Generic[_T]): |
| 54 | """Represent a PostgreSQL range. |
| 55 | |
| 56 | E.g.:: |
| 57 | |
| 58 | r = Range(10, 50, bounds="()") |
| 59 | |
| 60 | The calling style is similar to that of psycopg and psycopg2, in part |
| 61 | to allow easier migration from previous SQLAlchemy versions that used |
| 62 | these objects directly. |
| 63 | |
| 64 | :param lower: Lower bound value, or None |
| 65 | :param upper: Upper bound value, or None |
| 66 | :param bounds: keyword-only, optional string value that is one of |
| 67 | ``"()"``, ``"[)"``, ``"(]"``, ``"[]"``. Defaults to ``"[)"``. |
| 68 | :param empty: keyword-only, optional bool indicating this is an "empty" |
| 69 | range |
| 70 | |
| 71 | .. versionadded:: 2.0 |
| 72 | |
| 73 | """ |
| 74 | |
| 75 | lower: Optional[_T] = None |
| 76 | """the lower bound""" |
| 77 | |
| 78 | upper: Optional[_T] = None |
| 79 | """the upper bound""" |
| 80 | |
| 81 | bounds: _BoundsType = dataclasses.field(default="[)", kw_only=True) |
| 82 | empty: bool = dataclasses.field(default=False, kw_only=True) |
| 83 | |
| 84 | def __bool__(self) -> bool: |
| 85 | return not self.empty |
| 86 | |
| 87 | @property |
| 88 | def isempty(self) -> bool: |
| 89 | "A synonym for the 'empty' attribute." |
| 90 | |
| 91 | return self.empty |
| 92 | |
| 93 | @property |
| 94 | def is_empty(self) -> bool: |
| 95 | "A synonym for the 'empty' attribute." |
| 96 | |
| 97 | return self.empty |
| 98 | |
| 99 | @property |
| 100 | def lower_inc(self) -> bool: |
| 101 | """Return True if the lower bound is inclusive.""" |
| 102 | |
| 103 | return self.bounds[0] == "[" |
| 104 | |
| 105 | @property |
| 106 | def lower_inf(self) -> bool: |
| 107 | """Return True if this range is non-empty and lower bound is |
| 108 | infinite.""" |
| 109 | |
| 110 | return not self.empty and self.lower is None |
no outgoing calls