Skip to content

Commit 8fc6442

Browse files
committed
Warn about restriced typing.Literal
1 parent f196715 commit 8fc6442

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

docs/typing_syntax.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,21 @@ This expression allows adding shape and datatype information for data structures
102102
[Literals](https://typing.python.org/en/latest/spec/literal.html#literals) indicate a concrete value instead of type.
103103
Instead of using [`typing.Literal`](https://docs.python.org/3/library/typing.html#typing.Literal), you can enclose literal values in `{...}` in docstrings.
104104

105-
| Docstring type | Python type annotation |
106-
|----------------|------------------------|
107-
| `{1, 2, 3}` | `Literal[1, 2, 3]` |
108-
| `{1, 2, 3}` | `Literal[1, 2, 3]` |
105+
| Docstring type | Python type annotation |
106+
|---------------------------|----------------------------------|
107+
| `{-1, 0, 3, True, False}` | `Literal[-1, 0, 3, True, False]` |
108+
| `{"red", "blue", None}` | `Literal["red", "blue", None]` |
109109

110110
> [!TIP]
111111
> Enclosing a single value `{X}` is currently allowed but discouraged.
112112
> Instead consider the more explicit `Literal[X]`.
113113
114+
> [!WARNING]
115+
> Python's `typing.Literal` only supports a restricted set of parameters.
116+
> E.g., `float` literals are not yet supported by the type system but are allowed by docstub.
117+
> Addressing this use case is on the roadmap.
118+
> See [issue 47](https://github.com/scientific-python/docstub/issues/47) for more details.
119+
114120

115121
## reStructuredText role
116122

0 commit comments

Comments
 (0)