<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/python-type-checker-comparison-empty-container-inference-doklgkmap" -->

---
title: Python Type Checker Comparison: Empty Container Inference
description: Different Python type checkers handle inference of empty containers (like [] or {}) in distinct ways, each with trade-offs. Pyright, Ty, and Pyre infer Any for...
canonical: https://daily.dev/posts/python-type-checker-comparison-empty-container-inference-doklgkmap
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Python Type Checker Comparison: Empty Container Inference | daily.dev
og:description: Different Python type checkers handle inference of empty containers (like [] or {}) in distinct ways, each with trade-offs. Pyright, Ty, and Pyre infer Any for...
og:url: https://daily.dev/posts/python-type-checker-comparison-empty-container-inference-doklgkmap
og:image: https://api.daily.dev/og/posts/DokLgKMAp.png
og:image:alt: Python Type Checker Comparison: Empty Container Inference
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Type Checker Comparison: Empty Container Inference

**[Pyrefly: A Fast Python Type Checker and Language Server \| Pyrefly](https://daily.dev/sources/pyrefly)** · 8 min read · 0 upvotes · 0 comments

## Summary

Different Python type checkers handle inference of empty containers (like [] or {}) in distinct ways, each with trade-offs. Pyright, Ty, and Pyre infer Any for container elements, which produces the fewest errors but sacrifices type safety. Pytype infers types from all usages of the variable, closely mirroring runtime behavior but sometimes separating error locations from actual bugs. Mypy and Pyrefly infer from only the first usage, producing more actionable errors close to the bug's origin, though this heuristic can misjudge intent and cause false positives. Pyrefly defaults to first-use inference but allows disabling it to behave like Pyright.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://pyrefly.org/blog/container-inference-comparison>

## Questions this post answers

### How does Pyrefly infer the type of an empty list or dict when there's no type hint?

Pyrefly infers the container's element type based on the first usage of the variable after its creation, in syntactical order. For example, if a variable starts as an empty list and the first subsequent operation is appending an integer, Pyrefly infers list[int], and a later append of a string raises a type error unless the variable is explicitly annotated with a union type.

_Developers comparing Python type checker behavior can track detailed breakdowns like this on daily.dev._

### Why does Pyright infer Any for empty container elements instead of a more specific type?

Pyright, along with Ty and Pyre, infers Any for the elements of an empty container like [] because this approach requires no analysis of surrounding code context, making it the simplest and most efficient to implement. The tradeoff is reduced type safety: no false positives occur, but bugs like inserting the wrong type into a list can silently pass undetected and cause runtime crashes.

_daily.dev helps developers weighing type-safety tradeoffs across Python type checkers stay informed._

### What's the difference between Mypy's first-usage inference and Pytype's all-usages inference for empty containers?

Mypy infers a container's element type from only its first syntactical usage, so later inconsistent usages raise errors at the point closest to the actual bug, though it can produce false positives if that first usage misrepresents intent. Pytype instead unions the types from every usage of the container, which mirrors Python runtime behavior more closely but can place error messages far from the line that caused the bug.

_Teams debating type checker strategy for Python codebases can follow this kind of comparison on daily.dev._

## Similar posts on daily.dev

- [Python Type Checker Comparison: Typing Spec Conformance](https://daily.dev/posts/python-type-checker-comparison-typing-spec-conformance-yvjkxqkwd) · Hacker News · 1 upvotes · 0 comments
- [Pyrefly Now Type Checks PyTorch – PyTorch](https://daily.dev/posts/pyrefly-now-type-checks-pytorch-pytorch-adohlgdfc) · PyTorch · 0 upvotes · 0 comments
- [Pyrefly 1.0: A fast, forward-looking Python linter](https://daily.dev/posts/pyrefly-1-0-a-fast-forward-looking-python-linter-k4vukcqpr) · InfoWorld · 0 upvotes · 0 comments
- [In Python, you have to specify the type and not rely on inference](https://daily.dev/posts/in-python-you-have-to-specify-the-type-and-not-rely-on-inference-omb2z4wds) · Planet Python · 4 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python)

[View this post on daily.dev](https://daily.dev/posts/python-type-checker-comparison-empty-container-inference-doklgkmap)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Python Type Checker Comparison: Empty Container Inference","url":"https://daily.dev/posts/python-type-checker-comparison-empty-container-inference-doklgkmap","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/python-type-checker-comparison-empty-container-inference-doklgkmap"},"datePublished":"2026-08-23T12:17:27.274Z","dateModified":"2026-08-23T12:23:40.162Z","description":"Different Python type checkers handle inference of empty containers (like [] or {}) in distinct ways, each with trade-offs. Pyright, Ty, and Pyre infer Any for...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/ce7cceb523e1bdb0e6d2d6310d2d101d?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/ce7cceb523e1bdb0e6d2d6310d2d101d?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Pyrefly: A Fast Python Type Checker and Language Server | Pyrefly","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Pyrefly: A Fast Python Type Checker and Language Server | Pyrefly","logo":"https://media.daily.dev/image/upload/s--Qzw5NpnF--/c_limit,w_256/f_auto,q_auto/v1787487420/logos/pyrefly?_a=BAMAMicg0","url":"https://daily.dev/sources/pyrefly"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/python-type-checker-comparison-empty-container-inference-doklgkmap","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Pyrefly: A Fast Python Type Checker and Language Server | Pyrefly","item":"https://daily.dev/sources/pyrefly"},{"@type":"ListItem","position":3,"name":"Python Type Checker Comparison: Empty Container Inference"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/python-type-checker-comparison-empty-container-inference-doklgkmap#faq","mainEntity":[{"@type":"Question","name":"How does Pyrefly infer the type of an empty list or dict when there's no type hint?","acceptedAnswer":{"@type":"Answer","text":"Pyrefly infers the container's element type based on the first usage of the variable after its creation, in syntactical order. For example, if a variable starts as an empty list and the first subsequent operation is appending an integer, Pyrefly infers list[int], and a later append of a string raises a type error unless the variable is explicitly annotated with a union type. Developers comparing Python type checker behavior can track detailed breakdowns like this on daily.dev."}},{"@type":"Question","name":"Why does Pyright infer Any for empty container elements instead of a more specific type?","acceptedAnswer":{"@type":"Answer","text":"Pyright, along with Ty and Pyre, infers Any for the elements of an empty container like [] because this approach requires no analysis of surrounding code context, making it the simplest and most efficient to implement. The tradeoff is reduced type safety: no false positives occur, but bugs like inserting the wrong type into a list can silently pass undetected and cause runtime crashes. daily.dev helps developers weighing type-safety tradeoffs across Python type checkers stay informed."}},{"@type":"Question","name":"What's the difference between Mypy's first-usage inference and Pytype's all-usages inference for empty containers?","acceptedAnswer":{"@type":"Answer","text":"Mypy infers a container's element type from only its first syntactical usage, so later inconsistent usages raise errors at the point closest to the actual bug, though it can produce false positives if that first usage misrepresents intent. Pytype instead unions the types from every usage of the container, which mirrors Python runtime behavior more closely but can place error messages far from the line that caused the bug. Teams debating type checker strategy for Python codebases can follow this kind of comparison on daily.dev."}}]}
```

