frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Python Type Checker Comparison: Empty Container Inference

https://pyrefly.org/blog/container-inference-comparison/
25•ocamoss•4d ago

Comments

curiousgal•1h ago
I can't help but find type hints in python to be..goofy? I have a colleague who has a substantial C++ background and now working in python, the code is just littered with TypeAlias, Generic, cast, long Unions etc.. this can't be the way..
IshKebab•1h ago
I strongly disagree. Python has actually done a decent job of adding type annotations into the language IMO.

If you ignore the bit where they don't actually specify their semantics anyway.

> this can't be the way..

The alternative is fragile and unmaintainable code. I know which I prefer!

tialaramex•55m ago
Typing is a relatively easy way for the human author and the machine to notice if they disagree about what's going on before problems arise. It is unfortunate that Python doesn't do a good job with types, I was reading earlier today about the mess they made of booleans - their bool type is actually just the integers again.
nubg•34m ago
> I was reading earlier today about the mess they made of booleans

Can you elaborate on that?

IshKebab•5m ago
He did - booleans are integers:

  >>> isinstance(False, int)
  True
A related screw-up is implicitly casting everything to bool. A lot of languages made that mistake.

Overall I'd say they didn't do an awful job though. The main problems with Python are the absolutely abysmal tooling (which thankfully uv fixes), the abysmal performance (which sometimes isn't an issue, but it usually becomes an issue eventually), and the community's attitude to type checking.

Actually type checking code you've written yourself with Pyright in strict mode is quite a pleasant experience. But woe betide you if you want to import any third party libraries. There's at least a 50% chance they have no type annotations at all, and often it's deliberate. Typescript used to have a similar problem but the Javascript community realised a lot quicker than the Python community that type hints are a no-brainer.

wiseowise•42m ago
What is the way in your opinion?
IshKebab•1h ago
I think it would be worth mentioning that in normal use (strict mode) Pyright simply requires you to add type annotations to the declaration. Occasionally mildly annoying but IMO it's clearly the best option.
jez•1h ago
A more complicated version of this problem exists in TypeScript and Ruby, where there are only arrays. Python’s case is considerably simpler by also having tuples, whose length is fixed at the time of assignment.

In Python, `x = []` should always have a `list[…]` type inferred. In TypeScript and Ruby, the inferred type needs to account for the fact that `x` is valid to pass to a function which takes the empty tuple (empty array literal type) as well as a function that takes an array. So the Python strategy #1 in the article of defaulting to `list[Any]` does not work because it rejects passing `[]` to a function declared as taking `[]`.

Boxxed•1h ago
My favorite part about the type annotations in python is that it steers you into a sane subset of the language. I feel like it's kind of telling that python is this super dynamic language but the type annotations aren't powerful enough to denote all that craziness.
loevborg•50m ago
FWIW, Typescript is using Strategy 2: https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABM...

I'm a bit confused by the fact that the array starts out typed as `any[]` (e.g. if you hover over the declaration) but then, later on, the type gets refined to `(string | number)[]`. IMO it would be nicer if the declaration already showed the inferred type on hover.

bastawhiz•46m ago
It depends on your tsconfig. An empty array could be typed as never[], forcing you to annotate it.
loevborg•45m ago
Which setting specifically? Can you repro in the typescript playground?
wk_end•10m ago
I don't believe this is correct. There's no settings that correspond to that AFAIK, and it'd actually be quite bad, because you could access the empty array and then get a `never` object, which you're not supposed to be able to do.

https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABM...

`unknown[]` might be more appropriate as a default, but TypeScript does you one better: with OP's settings, although it's typed as `any[]`, it'll error out if you don't do anything to give it more information because of `noImplicitAny`.

Ghostty – Terminal Emulator

https://ghostty.org/docs
427•oli5679•7h ago•188 comments

Microgpt

http://karpathy.github.io/2026/02/12/microgpt/
1495•tambourine_man•18h ago•263 comments

Why XML Tags Are So Fundamental to Claude

https://glthr.com/XML-fundamental-to-Claude
91•glth•5h ago•48 comments

AWS Middle East Central Down, apparently struck in war

https://health.aws.amazon.com/health/status
45•earthboundkid•38m ago•11 comments

Decision trees – the unreasonable power of nested decision rules

https://mlu-explain.github.io/decision-tree/
315•mschnell•11h ago•57 comments

A new Polymarket account made over $500k betting on the U.S. strike against Iran

https://twitter.com/cabsav456/status/2027937130995921119
63•doener•40m ago•42 comments

Python Type Checker Comparison: Empty Container Inference

https://pyrefly.org/blog/container-inference-comparison/
26•ocamoss•4d ago•13 comments

How Dada Enables Internal References

https://smallcultfollowing.com/babysteps/blog/2026/02/27/dada-internal-references/
14•vrnvu•2d ago•5 comments

We do not think Anthropic should be designated as a supply chain risk

https://twitter.com/OpenAI/status/2027846016423321831
739•golfer•22h ago•406 comments

Flightradar24 for Ships

https://atlas.flexport.com/
123•chromy•9h ago•31 comments

When does MCP make sense vs CLI?

https://ejholmes.github.io/2026/02/28/mcp-is-dead-long-live-the-cli.html
100•ejholmes•3h ago•72 comments

I built a demo of what AI chat will look like when it's "free" and ad-supported

https://99helpers.com/tools/ad-supported-chat
361•nickk81•8h ago•220 comments

Interview with Øyvind Kolås, GIMP developer (2017)

https://www.gimp.org/news/2026/02/22/%C3%B8yvind-kol%C3%A5s-interview-ww2017/
87•ibobev•3d ago•35 comments

Microgpt explained interactively

https://growingswe.com/blog/microgpt
4•growingswe•10h ago•0 comments

Lil' Fun Langs' Guts

https://taylor.town/scrapscript-001
25•surprisetalk•4h ago•2 comments

Show HN: Audio Toolkit for Agents

https://github.com/shiehn/sas-audio-processor
19•stevehiehn•4h ago•1 comments

10-202: Introduction to Modern AI (CMU)

https://modernaicourse.org
180•vismit2000•12h ago•44 comments

New iron nanomaterial wipes out cancer cells without harming healthy tissue

https://www.sciencedaily.com/releases/2026/02/260228093456.htm
135•gradus_ad•4h ago•44 comments

Aromatic 5-silicon rings synthesized at last

https://cen.acs.org/materials/inorganic-chemistry/Aromatic-5-silicon-rings-synthesized/104/web/20...
59•keepamovin•2d ago•26 comments

The real cost of random I/O

https://vondra.me/posts/the-real-cost-of-random-io/
74•jpineman•3d ago•13 comments

Gzpeek: Tool to Parse Gzip Metadata

https://evanhahn.com/introducing-gzpeek/
3•ingve•2d ago•0 comments

Switch to Claude without starting over

https://claude.com/import-memory
486•doener•12h ago•225 comments

Why is the first C++ (m)allocation always 72 KB?

https://joelsiks.com/posts/cpp-emergency-pool-72kb-allocation/
102•joelsiks•10h ago•19 comments

An ode to houseplant programming (2025)

https://hannahilea.com/blog/houseplant-programming/
115•evakhoury•2d ago•23 comments

January in Servo: preloads, better forms, details styling, and more

https://servo.org/blog/2026/02/28/january-in-servo/
25•birdculture•2h ago•2 comments

Obsidian Sync now has a headless client

https://help.obsidian.md/sync/headless
553•adilmoujahid•1d ago•182 comments

Rydberg atoms detect clear signals from a handheld radio

https://phys.org/news/2026-02-rydberg-atoms-handheld-radio.html
65•Brajeshwar•2d ago•22 comments

Robust and efficient quantum-safe HTTPS

https://security.googleblog.com/2026/02/cultivating-robust-and-efficient.html
80•tptacek•2d ago•17 comments

The happiest I've ever been

https://ben-mini.com/2026/the-happiest-ive-ever-been
611•bewal416•3d ago•336 comments

Show HN: Vertex.js – A 1kloc SPA Framework

https://lukeb42.github.io/vertex-manual.html
23•LukeB42•8h ago•16 comments