Skip to content

Commit 67077ad

Browse files
authored
Reorder sections in FAQ (#3267)
Just a minor change to group all typing-related questions in one block.
1 parent 01144db commit 67077ad

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

docs/reference/typing-faq.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,20 @@ the developer experience around this in the future.
263263
You can check out the full example [here](https://play.ty.dev/7a1ea4ab-04e1-4271-adf5-ddc3a5d2fcfd),
264264
which demonstrates that `FileUpload` instances are no longer accepted by `retry`.
265265

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
278+
issue](https://github.com/astral-sh/ty/issues/1578).
279+
266280
## Does ty have a strict mode?
267281

268282
Not yet. A stricter inference mode is tracked in
@@ -378,17 +392,3 @@ No. ty does not have a plugin system and there is currently no plan to add one.
378392
We prefer extending the type system with well-specified features rather than relying on
379393
type-checker-specific plugins. That said, we are considering adding support for popular third-party
380394
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
394-
issue](https://github.com/astral-sh/ty/issues/1578).

0 commit comments

Comments
 (0)