frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Python argparse has a limitation on argument groups that makes me sad

https://utcc.utoronto.ca/~cks/space/blog/python/ArgparseAndNestedGroups
27•zdw•3d ago

Comments

lordkrandel•3d ago
True, it's annoying
mjevans•13h ago
Is there a standard python library that does annotate if an argument is user provided or instead (just) the default value?

This is extremely important for configuration priority. Program defaults (generally) should be the lowest priority level. Superseded by configuration files. Superseded by command-line arguments. Finally replaced by configuration changes during runtime. Notably each is (in theory) specified in a more specific context as well as more recently.

Neywiny•12h ago
I think this is doable but as an X vs Y problem. You can either not have a default and check if it's in the namespace later, or make the default value be the previously highest priority value as a run-time defined default. Do either of those work?
mjevans•11h ago
It would be nice if --help reports the (program) default as the default value for an option. A different option might dump a fully evaluated configuration. While a third might exit without doing anything.
dodslaser•12h ago
This can be done using click.
ErikBjare•12h ago
Not with multiple=True, since it then always returns an empty list and never None, even if the default is None.
NewsaHackO•13h ago
Can't you just generate all the groups by having a function the created a set of each individual timeout (--notimeout,--timeout-x) to pass to the parser?
bartread•12h ago
I wondered this as well. I must admit I’ve not yet written a command line tool (in Python) where I’ve needed what the author describes, but I did wonder if adding multiple exclusive groups with --notimeout as a member of all of the groups would do the trick. Perhaps you get an error or get into undefined behaviour territory but it would certainly be worth trying.
qwertox•12h ago
I mean, he does have a point, but his point has a solution: do not put them in mutually exclusive groups if they aren't mutually exclusive.

It seems more like this is a missing feature rather than an issue with mutually exclusive, if the desire is that `argparse` handles this in an elegant, internal way.

So, yes, `argparse` has a limitation on argument groups, but `add_mutually_exclusive_group` is not the issue.

looknee•12h ago
The gcloud CLI handles this using argparse, having a parent mutex group with one child —no-timeout flag and then a child group containing the timeout flags.
what•11h ago
But the docs say you can’t (or shouldn’t) add a child group because it’s not supported and will be removed…
xg15•10h ago
So the author wants a configuration, where I can either run the program with

--foo-timeout=5 --bar-timeout=10

or with

--no-timeouts

which disables the timeouts for both too and bar.

I don't know the author's entire usecase, but it seems odd that you would specifically NOT want the user to only disable one timeout, but keep all the others active.

Unless there is a real reason for this, the more logical design for me would be to treat --foo-timeout=0 or something as the setting to disable timeout foo.

Not sure if argparse supports aliases, but if it does, --no-timeouts could then be defined as an alias for "--foo-timeout=0 --bar-timeout=0 --baz-timeout=0" etc etc.

NoahZuniga•7h ago
They probably mean a combination like: I want the program to time out if the server response isn't done after 60 seconds I want the program to time out if the the last byte from the server is more than 10 seconds ago.

It doesn't make sense to say I want one of these timeouts and --no-timeout

The Art of Lisp and Writing

https://www.dreamsongs.com/ArtOfLisp.html
12•Bogdanp•1h ago•1 comments

Q-learning is not yet scalable

https://seohong.me/blog/q-learning-is-not-yet-scalable/
113•jxmorris12•7h ago•19 comments

Infinite Grid of Resistors

https://www.mathpages.com/home/kmath668/kmath668.htm
152•niklasbuschmann•10h ago•61 comments

I have reimplemented Stable Diffusion 3.5 from scratch in pure PyTorch

https://github.com/yousef-rafat/miniDiffusion
405•yousef_g•18h ago•69 comments

CI/CD Observability with OpenTelemetry Step by Step Guide

https://signoz.io/blog/cicd-observability-with-opentelemetry/
17•ankit01-oss•3d ago•1 comments

Breaking My Security Assignments

https://www.akpain.net/blog/breaking-secnet-assignments/
37•surprisetalk•2d ago•6 comments

AMD's AI Future Is Rack Scale 'Helios'

https://morethanmoore.substack.com/p/amds-ai-future-is-rack-scale-helios
70•rbanffy•11h ago•34 comments

Dance Captcha

https://dance-captcha.vercel.app/
32•edwinarbus•2d ago•7 comments

Chicken Eyeglasses

https://en.wikipedia.org/wiki/Chicken_eyeglasses
98•thomassmith65•4d ago•30 comments

Solar Orbiter gets world-first views of the Sun's poles

https://www.esa.int/Science_Exploration/Space_Science/Solar_Orbiter/Solar_Orbiter_gets_world-first_views_of_the_Sun_s_poles
220•sohkamyung•3d ago•29 comments

Waymo rides cost more than Uber or Lyft and people are paying anyway

https://techcrunch.com/2025/06/12/waymo-rides-cost-more-than-uber-or-lyft-and-people-are-paying-anyway/
339•achristmascarl•2d ago•590 comments

Inside the Apollo “8-Ball” FDAI (Flight Director / Attitude Indicator)

https://www.righto.com/2025/06/inside-apollo-fdai.html
142•zdw•17h ago•26 comments

Have a damaged painting? Restore it in just hours with an AI-generated “mask”

https://news.mit.edu/2025/restoring-damaged-paintings-using-ai-generated-mask-0611
60•WithinReason•2d ago•37 comments

The Algebra of an Infinite Grid of Resistors

https://www.mathpages.com/home/kmath669/kmath669.htm
4•gone35•2h ago•0 comments

Bioprospectors mine microbial genomes for antibiotic gold

https://cen.acs.org/pharmaceuticals/drug-discovery/Bioprospectors-mine-microbial-genomes-antibiotic/103/web/2025/06
9•bryanrasmussen•3d ago•1 comments

Last fifty years of integer linear programming: Recent practical advances

https://inria.hal.science/hal-04776866v1
193•teleforce•1d ago•60 comments

Meta-analysis of three different notions of software complexity

https://typesanitizer.com/blog/complexity-definitions.html
14•ingve•1d ago•1 comments

Wrong ways to use the databases, when the pendulum swung too far

https://www.luu.io/posts/2025-database-pendulum
78•luuio•2d ago•44 comments

Debunking HDR [video]

https://yedlin.net/DebunkingHDR/index.html
82•plastic3169•3d ago•45 comments

Fixing the mechanics of my bullet chess

https://jacobbrazeal.wordpress.com/2025/06/14/fixing-the-mechanics-of-my-bullet-chess/
32•tibbar•9h ago•18 comments

Cray versus Raspberry Pi

https://www.aardvark.co.nz/daily/2025/0611.shtml
96•flyingkiwi44•4d ago•74 comments

Unsupervised Elicitation of Language Models

https://arxiv.org/abs/2506.10139
126•kordlessagain•20h ago•18 comments

Endometriosis is an interesting disease

https://www.owlposting.com/p/endometriosis-is-an-incredibly-interesting
346•crescit_eundo•1d ago•237 comments

Seven replies to the viral Apple reasoning paper and why they fall short

https://garymarcus.substack.com/p/seven-replies-to-the-viral-apple
280•spwestwood•12h ago•210 comments

SIMD-friendly algorithms for substring searching (2016)

http://0x80.pl/notesen/2016-11-28-simd-strfind.html
210•Rendello•1d ago•32 comments

The Many Sides of Erik Satie

https://thereader.mitpress.mit.edu/the-many-sides-of-erik-satie/
144•anarbadalov•6d ago•32 comments

How to Build Conscious Machines

https://osf.io/preprints/thesiscommons/wehmg_v1
77•hardmaru•21h ago•76 comments

TimeGuessr

https://timeguessr.com/
287•stefanpie•5d ago•58 comments

Clinical knowledge in LLMs does not translate to human interactions

https://arxiv.org/pdf/2504.18919
81•insistent•10h ago•32 comments

Sperm are very different from all other cells

https://www.bbc.com/future/article/20250613-untangling-the-mysteries-of-what-we-dont-know-about-sperm
45•viewtransform•7h ago•33 comments