@@ -599,16 +599,19 @@ Basic operators
599599 member named ``S `` from the class ``T ``.
600600
601601
602- * ``GetSpecialAttr[T: type, Attr: Literal[str]] ``: Extracts the value
603- of the special attribute named ``Attr `` from the class ``T ``. Valid
604- attributes are ``__name__ ``, ``__module__ ``, and ``__qualname__ ``.
605- Returns the value as a ``Literal[str] ``.
606-
607-
608602* ``Length[T: tuple] `` - Gets the length of a tuple as an int literal
609603 (or ``Literal[None] `` if it is unbounded)
610604
611605
606+ * ``Slice[S: tuple, Start: Literal[int | None], End: Literal[int | None]] ``:
607+ Slices a tuple type.
608+
609+
610+ * ``GetSpecialAttr[T, Attr: Literal[str]] ``: Extracts the value
611+ of the special attribute named ``Attr `` from the class ``T ``. Valid
612+ attributes are ``__name__ ``, ``__module__ ``, and ``__qualname__ ``.
613+ Returns the value as a ``Literal[str] ``.
614+
612615All of the operators in this section are :ref: `lifted over union types
613616<lifting>`.
614617
@@ -684,7 +687,7 @@ Object creation
684687 items specified by the ``Member `` arguments.
685688
686689 .. TODO: Do we want a way to specify ``extra_items``?
687-
690+
688691 Note that we are not currently proposing any way to create *nominal * classes
689692or any way to make new *generic * types.
690693
@@ -725,34 +728,6 @@ Literal[0], 'kw_only': Literal[True]})]`` for the initializer, and
725728that would be made available as the ``Init `` field of the ``Member ``.
726729
727730
728- Annotated
729- '''''''''
730-
731- .. TODO: This could maybe be dropped if it doesn't seem implementable?
732-
733- Libraries like FastAPI use annotations heavily, and we would like to
734- be able to use annotations to drive type-level computation decision
735- making.
736-
737- Note that currently ``Annotated `` may be fully ignored by typecheckers.
738- The operations proposed are:
739-
740- * ``GetAnnotations[T] `` - Fetch the annotations of a potentially
741- Annotated type, as Literals. Examples::
742-
743- GetAnnotations[Annotated[int, 'xxx']] = Literal['xxx']
744- GetAnnotations[Annotated[int, 'xxx', 5]] = Literal['xxx', 5]
745- GetAnnotations[int] = Never
746-
747-
748- * ``DropAnnotations[T] `` - Drop the annotations of a potentially
749- Annotated type. Examples::
750-
751- DropAnnotations[Annotated[int, 'xxx']] = int
752- DropAnnotations[Annotated[int, 'xxx', 5]] = int
753- DropAnnotations[int] = int
754-
755-
756731Callable inspection and creation
757732''''''''''''''''''''''''''''''''
758733
@@ -789,29 +764,6 @@ Overloaded function types
789764* ``Overloaded[*Callables] `` - An overloaded function type, with the
790765 underlying types in order.
791766
792- String manipulation
793- '''''''''''''''''''
794-
795- String manipulation operations for string ``Literal `` types.
796-
797- ``Slice `` and ``Concat `` allow for basic literal template-like manipulation.
798- We can actually implement the case functions in terms of them and a
799- bunch of conditionals, but shouldn't (especially if we want it to work
800- for all unicode!).
801-
802-
803- * ``Slice[S: Literal[str] | tuple, Start: Literal[int | None], End: Literal[int | None]] ``:
804- Slices a ``str `` or a tuple type.
805-
806- * ``Concat[S1: Literal[str], S2: Literal[str]] ``: concatenate two strings
807-
808- * ``Uppercase[S: Literal[str]] ``: uppercase a string literal
809- * ``Lowercase[S: Literal[str]] ``: lowercase a string literal
810- * ``Capitalize[S: Literal[str]] ``: capitalize a string literal
811- * ``Uncapitalize[S: Literal[str]] ``: uncapitalize a string literal
812-
813- All of the operators in this section are :ref: `lifted over union types
814- <lifting>`.
815767
816768Raise error
817769'''''''''''
@@ -1121,6 +1073,8 @@ dataclasses-style method generation
11211073 *[x for x in typing.Iter[typing.Members[T]]],
11221074 ]
11231075
1076+ XXX: Update this test to have UpdateClass
1077+
11241078
11251079Rationale
11261080=========
@@ -1613,11 +1567,78 @@ We could do potentially better but it would require more machinery.
16131567* We would also need to do context sensitive type bound inference
16141568
16151569
1570+ Potential Future Extensions
1571+ ===========================
1572+
1573+ Support Manipulating Annotated
1574+ ------------------------------
1575+
1576+ Libraries like FastAPI use annotations heavily, and we would like to
1577+ be able to use annotations to drive type-level computation decision
1578+ making.
1579+
1580+ Note that currently ``Annotated `` may be fully ignored by
1581+ typecheckers, and so supporting inspection and manipulation of it
1582+ could end up being fraught.
1583+
1584+ One potential API for this might be:
1585+
1586+ * ``GetAnnotations[T] `` - Fetch the annotations of a potentially
1587+ Annotated type, as Literals. Examples::
1588+
1589+ GetAnnotations[Annotated[int, 'xxx']] = Literal['xxx']
1590+ GetAnnotations[Annotated[int, 'xxx', 5]] = Literal['xxx', 5]
1591+ GetAnnotations[int] = Never
1592+
1593+
1594+ * ``DropAnnotations[T] `` - Drop the annotations of a potentially
1595+ Annotated type. Examples::
1596+
1597+ DropAnnotations[Annotated[int, 'xxx']] = int
1598+ DropAnnotations[Annotated[int, 'xxx', 5]] = int
1599+ DropAnnotations[int] = int
1600+
1601+ String manipulation
1602+ '''''''''''''''''''
1603+
1604+ TypeScript has "template literal" types for strings that allow both
1605+ concatenating string literal types and decomposing them. They also
1606+ have a suite of capitalization related operations.
1607+
1608+ Supporting concatenation would allow use-cases such as generating new
1609+ method names based on attributes: for every attribute ``foo `` we could
1610+ generate a ``get_foo `` method.
1611+
1612+ Supporting slicing would allow doing more in-depth string traversals,
1613+ and supporting capitalization would allow operations like transforming
1614+ a name from ``snake_case `` to ``CapitalizedWords ``.
1615+
1616+ We can actually implement the case functions in terms of them and a
1617+ bunch of conditionals, but shouldn't (especially if we want it to work
1618+ for all unicode!).
1619+
1620+ It would definitely be possible to take just slicing and
1621+ concatenation, also.
1622+
1623+
1624+ * ``Slice[S: Literal[str], Start: Literal[int | None], End: Literal[int | None]] ``:
1625+ Also support slicing string types. (Currently tuples are supported.)
1626+
1627+ * ``Concat[S1: Literal[str], S2: Literal[str]] ``: concatenate two strings
1628+
1629+ * ``Uppercase[S: Literal[str]] ``: uppercase a string literal
1630+ * ``Lowercase[S: Literal[str]] ``: lowercase a string literal
1631+ * ``Capitalize[S: Literal[str]] ``: capitalize a string literal
1632+ * ``Uncapitalize[S: Literal[str]] ``: uncapitalize a string literal
1633+
1634+ All of the operators in this section are :ref: `lifted over union types
1635+ <lifting>`.
1636+
1637+ .. * Should we support building new nominal types??
1638+
16161639 Open Issues
16171640===========
16181641
1619- * Should we support building new nominal types??
1620-
16211642* What invalid operations should be errors and what should return ``Never ``?
16221643
16231644What exactly are the subtyping (etc) rules for unevaluated types
0 commit comments