Enchancement suggestion for argparse: intuit type from default

Ben Finney ben+python at benfinney.id.au
Wed Mar 14 09:19:15 EDT 2012


Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:

> On Wed, 14 Mar 2012 08:35:12 +1100, Ben Finney wrote:
> > That feels too magical to me. I don't see a need to special-case
> > that usage. There's not much burden in being explicit for the
> > argument type.
>
> And yet you are programming in Python instead of Java, Pascal or Ada
> :)

That's a good point :-)

> It's not magic at all, it's science! Or to be precise, it's a very simple 
> form of type inference

Right. I dislike proposals for run-time type inference in Python, since
they are too magical.

Especially since we're talking about user input (arguments from the
command line to the program); that requires more explicit declarations
and checking, not less.

> What if you want an argument --foo that will accept arbitrary types? Then 
> you would need some way to tell argparse not to infer the type from the 
> default.

So we would then need to special-case the special-case? Even more reason
to dislike this proposal.

> Explicit declarations should be used only for the uncommon cases where
> type inference cannot cope.

That's our point of disagreement, then: I think explicit declarations
should be required regarding user input.

-- 
 \              “Ridicule is the only weapon which can be used against |
  `\       unintelligible propositions.” —Thomas Jefferson, 1816-07-30 |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list