frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

OpenCiv3: Open-source, cross-platform reimagining of Civilization III

https://openciv3.org/
624•klaussilveira•12h ago•182 comments

The Waymo World Model

https://waymo.com/blog/2026/02/the-waymo-world-model-a-new-frontier-for-autonomous-driving-simula...
927•xnx•18h ago•548 comments

What Is Ruliology?

https://writings.stephenwolfram.com/2026/01/what-is-ruliology/
32•helloplanets•4d ago•24 comments

How we made geo joins 400× faster with H3 indexes

https://floedb.ai/blog/how-we-made-geo-joins-400-faster-with-h3-indexes
109•matheusalmeida•1d ago•27 comments

Jeffrey Snover: "Welcome to the Room"

https://www.jsnover.com/blog/2026/02/01/welcome-to-the-room/
9•kaonwarb•3d ago•7 comments

Unseen Footage of Atari Battlezone Arcade Cabinet Production

https://arcadeblogger.com/2026/02/02/unseen-footage-of-atari-battlezone-cabinet-production/
40•videotopia•4d ago•1 comments

Show HN: Look Ma, No Linux: Shell, App Installer, Vi, Cc on ESP32-S3 / BreezyBox

https://github.com/valdanylchuk/breezydemo
219•isitcontent•13h ago•25 comments

Monty: A minimal, secure Python interpreter written in Rust for use by AI

https://github.com/pydantic/monty
210•dmpetrov•13h ago•103 comments

Show HN: I spent 4 years building a UI design tool with only the features I use

https://vecti.com
322•vecti•15h ago•143 comments

Sheldon Brown's Bicycle Technical Info

https://www.sheldonbrown.com/
370•ostacke•18h ago•94 comments

Microsoft open-sources LiteBox, a security-focused library OS

https://github.com/microsoft/litebox
358•aktau•19h ago•181 comments

Hackers (1995) Animated Experience

https://hackers-1995.vercel.app/
477•todsacerdoti•20h ago•232 comments

Show HN: If you lose your memory, how to regain access to your computer?

https://eljojo.github.io/rememory/
272•eljojo•15h ago•160 comments

An Update on Heroku

https://www.heroku.com/blog/an-update-on-heroku/
402•lstoll•19h ago•271 comments

Dark Alley Mathematics

https://blog.szczepan.org/blog/three-points/
85•quibono•4d ago•20 comments

Vocal Guide – belt sing without killing yourself

https://jesperordrup.github.io/vocal-guide/
14•jesperordrup•2h ago•7 comments

Delimited Continuations vs. Lwt for Threads

https://mirageos.org/blog/delimcc-vs-lwt
25•romes•4d ago•3 comments

PC Floppy Copy Protection: Vault Prolok

https://martypc.blogspot.com/2024/09/pc-floppy-copy-protection-vault-prolok.html
56•kmm•5d ago•3 comments

Start all of your commands with a comma

https://rhodesmill.org/brandon/2009/commands-with-comma/
3•theblazehen•2d ago•0 comments

Was Benoit Mandelbrot a hedgehog or a fox?

https://arxiv.org/abs/2602.01122
12•bikenaga•3d ago•2 comments

How to effectively write quality code with AI

https://heidenstedt.org/posts/2026/how-to-effectively-write-quality-code-with-ai/
244•i5heu•15h ago•189 comments

Introducing the Developer Knowledge API and MCP Server

https://developers.googleblog.com/introducing-the-developer-knowledge-api-and-mcp-server/
52•gfortaine•10h ago•21 comments

I spent 5 years in DevOps – Solutions engineering gave me what I was missing

https://infisical.com/blog/devops-to-solutions-engineering
140•vmatsiiako•17h ago•63 comments

Understanding Neural Network, Visually

https://visualrambling.space/neural-network/
280•surprisetalk•3d ago•37 comments

I now assume that all ads on Apple news are scams

https://kirkville.com/i-now-assume-that-all-ads-on-apple-news-are-scams/
1058•cdrnsf•22h ago•433 comments

Why I Joined OpenAI

https://www.brendangregg.com/blog/2026-02-07/why-i-joined-openai.html
132•SerCe•8h ago•117 comments

Show HN: R3forth, a ColorForth-inspired language with a tiny VM

https://github.com/phreda4/r3
70•phreda4•12h ago•14 comments

Female Asian Elephant Calf Born at the Smithsonian National Zoo

https://www.si.edu/newsdesk/releases/female-asian-elephant-calf-born-smithsonians-national-zoo-an...
28•gmays•8h ago•11 comments

Learning from context is harder than we thought

https://hy.tencent.com/research/100025?langVersion=en
176•limoce•3d ago•96 comments

FORTH? Really!?

https://rescrv.net/w/2026/02/06/associative
63•rescrv•20h ago•22 comments
Open in hackernews

Use keyword-only arguments in Python dataclasses

https://chipx86.blog/2025/06/29/tip-use-keyword-only-arguments-in-python-dataclasses/
95•Bogdanp•7mo ago

Comments

flakes•7mo ago
You could argue the same thing (forcing kwargs) for all Python functions/methods, although, that would make using your APIs very annoying. The `__init__` method for dataclasses are just another method like any other.

As a general rule of thumb, I only start forcing kwargs once I'm looking at above 4-5 arguments, or if the arguments are similar enough that forcing kwargs makes the calling code more readable. For a small number of distinct arguments, forcing kwargs as a blanket rule makes the code verbose for little gain IMO.

masklinn•7mo ago
> You could argue the same thing (forcing kwargs) for all Python functions/methods, although, that would make using your APIs very annoying. The `__init__` method for dataclasses are just another method like any other.

While that is self evident at a technical level, it is not quite so from a clarity / documentary perspective: “normal” functions and methods can often hint at their parameters through their naming but it is uncommon for types, for which the composite tends to be much more of an implementation detail.

Of course neither rule is universal e.g. the composite is of prime importance for newtypes, and indeed they often use tuple-style types or have special support with no member names.

vbezhenar•7mo ago
> that would make using your APIs very annoying

For Objective C, using named parameters is the only way to call methods. I don't think I read many critique about this particular aspect. IMO it's actually a good thing and increases readability quite a bit.

For JavaScript/TypeScript React codebase, using objects as a poor man's named parameters also very popular approach.

Also I'd like to add, that it seems a recent trend to add feature to IDEs, where it'll add hint for every parameter, somewhat simulating named parameters. So when you write `mymethod(value)`, it'll display it as `mymethod(param:value)`.

So may be not very annoying.

The only little thing I'd like to borrow from JavaScript is using "shortcut", so you could replace `x=x` with `x`, if your local variable happened to have the same name, as parameter name (which happens often enough).

laserlight•7mo ago
To be pedantic, Objective-C doesn't have named parameters. Method names are composed of multiple parts, each corresponding to a parameter. Such design contributes to the method's readability and memorability. In contrast, Python methods have their own names, and parameter names are chosen as an afterthought. While there's no reason why Python methods couldn't be named in accordance with parameter names, unfortunately it hasn't been a part of Python's culture.
int_19h•7mo ago
I find that anything above 2 arguments benefits from explicit keyword notation. With 4-5 arguments, especially when most of them are of the same type, it can be difficult to tell which is which.
joshdavham•7mo ago
> Positional arguments means a caller can use MyDataClass(1, 'foo', False), and if you remove/reorder any of these arguments, you’ll break those callers unexpectedly. By forcing callers to use MyDataClass(x=1, y='foo', z=False), you remove this risk.

This is an awesome way to prevent future breaking changes!

...but unfortunately, adding this to an existing project would also likely result in breakings changes haha

chipx86•7mo ago
That's always the challenge when iterating on interfaces that other people depend on.

What we do is go through a deprecation phase. Our process is:

* We provide compatibility with the old signature for 2 major releases.

* We document the change and the timeline clearly in the docstring.

* The function gets decorated with a helper that checks the call, and if any keyword-only arguments are provided as positional, it warns and converts them to keyword-only.

* After 2 major releases, we move fully to the new signature.

We buit a Python library called housekeeping (https://github.com/beanbaginc/housekeeping) to help with this. One of the things it contains is a decorator called `@deprecate_non_keyword_only_args`, which takes a deprecation warning class and a function using the signature we're moving to. That decorator handles the check logic and generates a suitable, consistent deprecation message.

That normally looks like:

    @deprecate_non_keyword_only_args(MyDeprecationWarning)
    def my_func(*, a, b, c):
        ...
But this is a bit more tricky with dataclasses, since `__init__()` is generated automatically. Fortunately, it can be patched after the fact. A bit less clean, but doable.

So here's how we'd handle this case with dataclasses:

    from dataclasses import dataclass
    
    from housekeeping import BaseRemovedInWarning, deprecate_non_keyword_only_args
    
    
    class RemovedInMyProject20Warning(BaseRemovedInWarning):
        product = 'MyProject'
        version = '2.0'
    
    
    @dataclass(kw_only=True)
    class MyDataclass:
        a: int
        b: int
        c: str
    
    MyDataclass.__init__ = deprecate_non_keyword_only_args(
        RemovedInMyProject20Warning
    )(MyDataclass.__init__)

Call it with some positional arguments:

    dc = MyDataclass(1, 2, c='hi')

and you'd get:

    testdataclass.py:26: RemovedInMyProject20Warning: Positional arguments `a`, `b` must be passed as keyword arguments when calling `__main__.MyDataclass.__init__()`. Passing as positional arguments will be required in MyProject 2.0.
      dc = MyDataclass(1, 2, c='hi')

We'll probably add explicit dataclass support to this soon, since we're starting to move to kw_only=True for dataclasses.
codethief•7mo ago
Shouldn't you also be able to patch MyDataclass in a class decorator (on top of/after @dataclass)?
chipx86•7mo ago
Yeah, that's the approach we'll be taking in housekeeping. I didn't want to complicate the example any more than I already did :)
Lutger•7mo ago
Even better is ... just not breaking the interface, leave the code be.

Add parameters at the end. Or just add a new function. Or even a new module if things get too messy for your liking.

Just leave the old users in peace. If you are worried about breaking stuff, it means people are using the function you wrote and find value in it. Why change it at all? I think it is very rare that the reasons for breaking are so compelling that they are worth the trouble.

ziml77•7mo ago
But the problem here is that with a dataclass you never explicitly defined any parameters. It's the dataclass annotation that defined them for the constructor based on the order of the fields. So, yes the solution is to never re-order the fields and only add new ones to the end, but this can be a surprising requirement because normally the order of fields in a class doesn't matter to users of the class.
FridgeSeal•7mo ago
Oh man, the aws Boto3 library does this for a huge number of calls, and it’s awful.

“What parameters does this take?” you ask, “why, it takes ‘kwargs’” responds the docs and your IDE.

How incredibly helpful!

chipx86•7mo ago
That's annoying for sure. Though a different problem.

All the kw_only=True argument for dataclasses does is require that you pass any fields you want to provide as keyword arguments instead of positional arguments when instantiating a dataclass. So:

    obj = MyDataclass(a=1, b=2, c=3)
Instead of:

    obj = MyDataclass(1, 2, 3)  # This would be an error with kw_only=True
The problem you're describing in boto3 (and a lot of other API bindings, and a lot of more layered Python code) is that methods often take in **kwargs and pass them down to a common function that's handling them. From the caller's perspective, **kwargs is a black box with no details on what's in there. Without a docstring or an understanding of the call chain, it's not helpful.

Python sort of has a fix for this now, which is to use a TypedDict to define all the possible values in the **kwargs, like so:

    from typing import TypedDict, Unpack


    class MyFuncKwargs(TypedDict):
        arg1: str
        arg2: str
        arg3: int | None


    def my_outer_func(
        **kwargs: Unpack[MyFuncKwargs],
    ) -> None:
        _my_inner_func(**kwargs)


    def _my_inner_func(
        *,
        arg1: str,
        arg2: str,
        arg3: int | None,
    ) -> None:
        ...
By defining a TypedDict and typing **kwargs, the IDE and docs can do a better job of showing what arguments the function really takes, and validating them.

Also useful when the function is just a wrapper around serializing **kwargs to JSON for an API, or something.

But this feature is far from free to use. The more functions you have, the more of these you need to create and maintain.

Ideally, a function could type **kwargs as something like:

    def my_outer_func(
        **kwargs: KwargsOf[_my_inner_func],
    ) -> None:
        ...
And then the IDEs and other tooling can just reference that function. This would help make the problem go away for many of the cases where **kwargs is used and passed around.
mvieira38•7mo ago
TypedDicts are so underutilized in general. I'm using them a lot even for simpler scripts
maleldil•7mo ago
I don't see a point in using them in new code when I could just use a dataclass (or Pydantic in certain contexts). I've only found them useful when interfacing with older code that uses dicts for structured data.
DanielVZ•7mo ago
In boto3 it helps to add a stubs package for development (and type checking).
FridgeSeal•7mo ago
Next time I am subjected to Python, I’ll use this for sure, thank you.
DanielVZ•7mo ago
Love the wording. I really like python but I can see why a lot of people don’t.
guappa•7mo ago
When I was plagued by having to use elasticsearch, the python client we used had the same issue. Every function took kwargs.
Sohcahtoa82•7mo ago
Boto3 in general is just an utter pain in the ass to work with. It's like they did everything they could to go out of their way to make sure your IDE couldn't figure out how to do anything.

Like, why the hell did they use strings to decide what kind of client you want? Why make us do `s3 = boto3.client('s3')` instead of `s3 = boto3.client.s3()` or something similar? It means my IDE can't figure out what the type of `s3` is.

Everything about it is so unpythonic. Functions and classes in it might use the Python snake_case, but keyword arguments use PascalCase.

I've often considered writing a wrapper around it to provide a sane interface to the AWS API, but the amount of functionality is so vast that it would be a massive undertaking.

ayhanfuat•7mo ago
I like keyword-only arguments, but they become tedious too quickly - especially when the variable names already match (fn(x=x, y=y, z=z)). I wish Python had JavaScript’s shorthand property syntax. (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...).
sweetgiorni•7mo ago
Python 3.14 adds that shorthand, but with a slight different (and IMO uglier) syntax:

  fn(x=,y=,z=)
https://peps.python.org/pep-0736/

edit: nevermind, that PEP was rejected :/

pansa2•7mo ago
That PEP says “rejected”
snickerdoodle12•7mo ago
Thankfully so. As much as I want a shorthand, this syntax wasn't it.
vovavili•7mo ago
By the look of it, the feeling I get is that a decent and convenient syntax proposal has been bikeshedded into rejection. Some particular form of keyword arguments at invocation would definitely make quite a few of my scripts more readable.
dgan•7mo ago
there should definitely be an ocaml-like equivalent of "~argument"
toolslive•7mo ago
it's also a gentle force towards consistent naming, ie having the same name on caller and callee site.
jampekka•7mo ago
JS's shorthand property syntax is lovely and elegant. Python can't really adopt it though as it clashes with the set syntax (which is such a niche use case it really shouldn't have a special syntax).

You could do something like f(**{x, y, z}) with just that. Not the prettiest, but at least it would be DRY.

But in general Python devs seem to prefer "explicit" ad-hoc syntax for each use case instead of composable "primitives". Which is approaching a kind of C++ situation where relatively few users know the syntax comprehensively.

data-ottawa•7mo ago
Julia uses a semicolon prefix in a tuple to denote this restructuring. I think that could fit into Python without breaking the whole ecosystem.
bobbylarrybobby•7mo ago
Python would probably just use the asterisk to mimic the syntax used to declare kw-only kwargs.

def f(x, , y): ...

f(foo,

, y)

bvrmn•7mo ago
> But in general Python devs seem to prefer "explicit" ad-hoc syntax for each use case instead of composable "primitives".

I hope you don't consider JS having "composable primitives". To backup my point: there is no anything similar to underscore-like libraries for Python. All is covered by stdlib and syntax.

> for(in) / for(of)

Cough, cough.

jampekka•7mo ago
Libraries like underscore are possible because of JS having composable primitives.

JS has many many warts, and the for-loop is a good example of this. And the _.each is a good example how the core JS allows for working around it.

bvrmn•7mo ago
But underscore is literally a bunch of functions taking lambdas. Python also has functions and lambdas. [1] shows it could provide the same interface. I don't get what composable primitives JS has.

[1]: https://pydash.readthedocs.io/en/latest/

joshdavham•7mo ago
Are there other ways to get this argument-enforcing behaviour in functions, not just data classes?
pansa2•7mo ago
Keyword-only arguments? Yes:

https://peps.python.org/pep-3102/

More recently, Python also added support for positional-only parameters:

https://peps.python.org/pep-0570/

est•7mo ago
I tried using python dataclasses in some projects, the only complaint is that I can not directly pass any dict to a dataclass but have to lint only supported keys.

I think a better way to init a dataclass would be something like `mydataclass(my_dict, lint=True)` instead of passing values as kwargs.

x187463•7mo ago
What do you mean pass a dict? As in kwargs?

    kwargs = {'arg1':'val1', 'arg2':'val2'}
    my_obj = MyDataclass(**kwargs)
Works fine for a dataclass with arg1 and arg2 attributes.
never_inline•7mo ago
Doesnt work recursively?
maleldil•7mo ago
At that point, you probably want proper validation with something like Pydantic, where you can use MyType.model_validate(dict).
est•7mo ago
i mean if `arg2` wasn't defined in MyDataclass, there would an error. You have to exclude fields first.
meander_water•7mo ago
You can also explicitly specify which arguments need to be keyword only using the KW_ONLY sentinel type annotation:

  from dataclasses import KW_ONLY

  @dataclass
  class Point:
      x: float
      _: KW_ONLY
      y: float
      z: float

  p = Point(0, y=1.5, z=2.0)
mixedmath•7mo ago
I've never seen this before. But yes, this does work. And that's very nice.

Thank you for the tip.

chipx86•7mo ago
This is a great feature for those who want a mix of positional and keyword-only arguments.

I should have mentioned originally (and I've since updated my post) that this and the kw_only= flag both require Python 3.10 and higher, so code that works with older versions can't opt into it yet.

eachro•7mo ago
Is there a reason to use data classes over pedantic base models anymore?
gjvc•7mo ago
did you mean: "pydantic base models" ?
eachro•7mo ago
Yeah haha I got autocorrected
alfons_foobar•7mo ago
I guess some prefer to stick with the stdlib instead of third party libs.

Also, dataclasses feels more straightforward and less "magic" to me (in the sense that it is more or less "just" a way to avoid boilerplate for class definition, while pydantic does way more "magic" stuff like de-/serialization and validation, and adding numerous methods and attributes to the classes).

guappa•7mo ago
speed? Not pulling in a huge dependency?
mvieira38•7mo ago
Speed and size, mainly. If you don't need the data validation there's no reason to use pydantic, it's a huge dependency
JimDabell•7mo ago
I’ve never really gotten along with Pydantic. Something about it just doesn’t feel ergonomic.

If I need something more than dataclasses, I’ll normally go for attrs/cattrs. Dataclasses were originally based on attrs, so it’s not much of a leap.

LtWorf•7mo ago
I never understood why basemodel even exists.

When I started to implement typedload, when types were just introduced, I supported NamedTuple, and then as more things were added, also attrs, dataclasses, typed dict…

What would be the point to require migrating the whole codebase to use something different to use your library?

On the other hand, if you wrote your code from scratch to use basemodel you're pretty much stuck with pydantic.

semiinfinitely•7mo ago
I need another blog like this but for slots=True
spstoyanov•7mo ago
Nice! Explicit is better.