Issue41087
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2020-06-23 08:42 by Bryan, last changed 2022-04-11 14:59 by admin. This issue is now closed.
Messages (8) | |||
---|---|---|---|
msg372143 - (view) | Author: Bryan (Bryan) | Date: 2020-06-23 08:42 | |
parser.add_argument('-e', '--Edge', type = int, default = 0.005, metavar = 'Edge') Runs fine. Script uses default of 0.005 even when int specified. But if user tries to change, not an int.... |
|||
msg372144 - (view) | Author: Karthikeyan Singaravelan (xtreak) * | Date: 2020-06-23 08:47 | |
There is a documentation note on type casting along with an example similar to the report https://docs.python.org/3.8/library/argparse.html#default > If the default value is a string, the parser parses the value as if it were a command-line argument. In particular, the parser applies any type conversion argument, if provided, before setting the attribute on the Namespace return value. Otherwise, the parser uses the value as is: |
|||
msg372145 - (view) | Author: Bryan (Bryan) | Date: 2020-06-23 08:49 | |
Maybe so, But, the issue is, if it trips up a user when they try to use the option, it should trip up the dev when the default is used... On Tue, 23 Jun 2020 18:47 Karthikeyan Singaravelan, <report@bugs.python.org> wrote: > > Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment: > > There is a documentation note on type casting along with an example > similar to the report > https://docs.python.org/3.8/library/argparse.html#default > > > If the default value is a string, the parser parses the value as if it > were a command-line argument. In particular, the parser applies any type > conversion argument, if provided, before setting the attribute on the > Namespace return value. Otherwise, the parser uses the value as is: > > ---------- > nosy: +paul.j3, rhettinger, xtreak > type: -> behavior > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue41087> > _______________________________________ > |
|||
msg372182 - (view) | Author: paul j3 (paul.j3) * | Date: 2020-06-23 16:20 | |
No, parameters like `type` let the developer control what his users provides. Violating that produces a runtime error, and exit. But in general argparse does not try to control values that the developer uses. There's plenty of time during development to catch error such as this - if they are errors at all. 'type' does not 'declare' what the attribute will be. It is a function that is applied to the input string, and converts that to something or other, or raises a TypeError. It is used only if there is a string value to work on, either from the user, or a string default. This is not a bug, so should be closed. |
|||
msg372184 - (view) | Author: Bryan (Bryan) | Date: 2020-06-23 17:06 | |
This sort of ambiguity is why I like strongly typed languages and languages where timtoady is not seen often. I can guarantee you, that if argparse was implemented in Pascal (and copt most probably has been), that if type was specified and a default given, that the default would have to adhere to that type. It is just programming common sense.... On Wed, 24 Jun 2020 02:20 paul j3, <report@bugs.python.org> wrote: > > paul j3 <ajipanca@gmail.com> added the comment: > > No, parameters like `type` let the developer control what his users > provides. Violating that produces a runtime error, and exit. > > But in general argparse does not try to control values that the developer > uses. There's plenty of time during development to catch error such as > this - if they are errors at all. > > 'type' does not 'declare' what the attribute will be. It is a function > that is applied to the input string, and converts that to something or > other, or raises a TypeError. It is used only if there is a string value > to work on, either from the user, or a string default. > > This is not a bug, so should be closed. > > ---------- > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue41087> > _______________________________________ > |
|||
msg372186 - (view) | Author: Vedran Čačić (veky) * | Date: 2020-06-23 17:31 | |
Yes, it is common sense in statically typed languages. Python is not statically typed. Many other things are also "common sense" in various paradigms, which doesn't mean they should also be in Python. |
|||
msg372189 - (view) | Author: Bryan (Bryan) | Date: 2020-06-23 17:46 | |
So you agree, Python lacks common sense... On Wed, 24 Jun 2020 at 03:32, Vedran Čačić <report@bugs.python.org> wrote: > > Vedran Čačić <vedgar@gmail.com> added the comment: > > Yes, it is common sense in statically typed languages. Python is not > statically typed. Many other things are also "common sense" in various > paradigms, which doesn't mean they should also be in Python. > > ---------- > nosy: +veky > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue41087> > _______________________________________ > |
|||
msg372305 - (view) | Author: Vedran Čačić (veky) * | Date: 2020-06-25 06:58 | |
Python _is_ strongly typed. As soon as you try to use that 0.005 as an index into a list or something else that requires an int, you'll get a TypeError. Strong typing is not the same as static typing. It is a common misconception. And common sense is always common to something. For humans it is common sense that we have two eyes, but it's not common to spiders. As I said, what is common sense in statically typed languages is not necessarily common to Python. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:59:32 | admin | set | github: 85259 |
2020-06-25 06:58:25 | veky | set | messages: + msg372305 |
2020-06-23 17:55:49 | serhiy.storchaka | set | status: open -> closed resolution: not a bug stage: resolved |
2020-06-23 17:46:09 | Bryan | set | messages: + msg372189 |
2020-06-23 17:31:52 | veky | set | nosy:
+ veky messages: + msg372186 |
2020-06-23 17:06:00 | Bryan | set | messages: + msg372184 |
2020-06-23 16:20:44 | paul.j3 | set | messages: + msg372182 |
2020-06-23 08:49:50 | Bryan | set | messages: + msg372145 |
2020-06-23 08:47:23 | xtreak | set | nosy:
+ rhettinger, xtreak, paul.j3 type: behavior messages: + msg372144 |
2020-06-23 08:42:21 | Bryan | create |