Am 25.03.2020 um 10:34 schrieb Justin Pryzby:
I think I would leave the "positive" variable names, and *add* negative forms
of the commandline options. --no-foo and/or --foo=no
Yes, that would be nice. Unfortunately, the options are not interpreted
by us, but by distutils. The way the options are currently defined in
PyGreSQL they act as booleans that do not take arguments, i.e. you can
set --foo, but not --foo=false. Unfortunately how the options are
interpreted is not well documented (at least I find nothing), so I had
to look into the Python source and found distutils uses getopt to parse
the raw options. Therefore it is possible to require arguments by
writing a "=" after the name of the argument in user_options, e.g.
('escaping-funcs=', None, "enable string escaping functions"),
When defined that way, we will be able to pass "--escaping-funcs=no" or
"--escaping-funcs false" as an option. When 'escaping-funcs' is added to
boolean_options, then the argument needs to be something like 0/false/no
or 1/true/yes and will be converted to a Python bool.
Unfortunately, getopt does not allow default arguments. So it looks like
we have to choose between:
1) Either two options --escaping-funcs and --no-escaping-funcs, both
without arguments or
2) one option --escaping funcs with a mandatory boolean argument
In both cases, when we set self.escaping_funcs = None in
initialize_options, we can implement the ternary on/off/default.
Not sure whether 1) or 2) is better, what do you think?
PyGreSQL mailing list