You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/typing-faq.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -263,6 +263,20 @@ the developer experience around this in the future.
263
263
You can check out the full example [here](https://play.ty.dev/7a1ea4ab-04e1-4271-adf5-ddc3a5d2fcfd),
264
264
which demonstrates that `FileUpload` instances are no longer accepted by `retry`.
265
265
266
+
## What is `Top[list[Unknown]]`, and why does it appear?
267
+
268
+
This type represents "all possible lists of any element type" (as opposed to `list[Unknown]`, which
269
+
represents "a list of some unknown element type"). It usually arises from a check such as
270
+
`if isinstance(x, list):`. If `x` was previously of type `Item | list[Item]`, you might expect this
271
+
check to narrow the type to `list[Item]`, but ty respects the possibility that there could be a
272
+
common subclass of both `Item` and `list` (which may not be a list of `Item`!), and so the narrowed
273
+
type is instead `(Item & Top[list[Unknown]]) | list[Item]`. This code can be made more robust by
274
+
instead checking `if instance(x, Item)`, or by declaring the `Item` type as `@typing.final`.
275
+
276
+
See also the [discussion
277
+
here](https://docs.astral.sh/ty/features/type-system/#top-and-bottom-materializations) and [in this
@@ -378,17 +392,3 @@ No. ty does not have a plugin system and there is currently no plan to add one.
378
392
We prefer extending the type system with well-specified features rather than relying on
379
393
type-checker-specific plugins. That said, we are considering adding support for popular third-party
380
394
libraries like pydantic, SQLAlchemy, attrs, or django directly into ty.
381
-
382
-
## What is `Top[list[Unknown]]`, and why does it appear?
383
-
384
-
This type represents "all possible lists of any element type" (as opposed to `list[Unknown]`, which
385
-
represents "a list of some unknown element type"). It usually arises from a check such as
386
-
`if isinstance(x, list):`. If `x` was previously of type `Item | list[Item]`, you might expect this
387
-
check to narrow the type to `list[Item]`, but ty respects the possibility that there could be a
388
-
common subclass of both `Item` and `list` (which may not be a list of `Item`!), and so the narrowed
389
-
type is instead `(Item & Top[list[Unknown]]) | list[Item]`. This code can be made more robust by
390
-
instead checking `if instance(x, Item)`, or by declaring the `Item` type as `@typing.final`.
391
-
392
-
See also the [discussion
393
-
here](https://docs.astral.sh/ty/features/type-system/#top-and-bottom-materializations) and [in this
0 commit comments