[Python] fix and improve default argument handling
1. Fix negative octals. Currently not handled correctly by `-py3`
(unusual case, but incorrect).
2. Fix arguments of type "octal + something" (e.g. `0640 | 04`).
Currently drops everything after the first octal. Nasty!
3. Fix bool arguments "0 + something" (e.g. `0 | 1`) are always
"False" (unusual case, but incorrect).
4. Remove special handling of "TRUE" and "FALSE" from
`convertValue` since there's no reason these have to match
"true" and "false".
5. Remove the Python 2 vs. Python 3 distinction based on the
`-py3` flag. Now the same python code is produced for default
arguments for Python 2 and Python 3. For this, octal default
arguments, e.g. 0644, are now wrapped as `int('644', 8)`. This
is required, as Python 2 and Python 3 have incompatible syntax
for octal literals.
Fixes #707
This commit is contained in:
parent
057b1dc028
commit
80ffb169c1
4 changed files with 129 additions and 105 deletions
|
|
@ -115,15 +115,39 @@ def run(module_name):
|
|||
if Klass_inc().val != 0:
|
||||
raise RuntimeError("Klass::inc failed")
|
||||
|
||||
default_args.trickyvalue1(10)
|
||||
default_args.trickyvalue1(10, 10)
|
||||
default_args.trickyvalue2(10)
|
||||
default_args.trickyvalue2(10, 10)
|
||||
default_args.trickyvalue3(10)
|
||||
default_args.trickyvalue3(10, 10)
|
||||
tricky_failure = False
|
||||
tricky = default_args.TrickyInPython()
|
||||
if tricky.value_m1(10) != -1:
|
||||
print "trickyvalue_m1 failed"
|
||||
tricky_failure = True
|
||||
if tricky.value_m1(10, 10) != 10:
|
||||
print "trickyvalue_m1 failed"
|
||||
tricky_failure = True
|
||||
if tricky.value_0xabcdef(10) != 0xabcdef:
|
||||
print "trickyvalue_0xabcdef failed"
|
||||
tricky_failure = True
|
||||
if tricky.value_0644(10) != 420:
|
||||
print "trickyvalue_0644 failed"
|
||||
tricky_failure = True
|
||||
if tricky.value_perm(10) != 420:
|
||||
print "trickyvalue_perm failed"
|
||||
tricky_failure = True
|
||||
if tricky.value_m01(10) != -1:
|
||||
print "trickyvalue_m01 failed"
|
||||
tricky_failure = True
|
||||
if not tricky.booltest2():
|
||||
print "booltest2 failed"
|
||||
tricky_failure = True
|
||||
|
||||
if tricky_failure:
|
||||
raise RuntimeError
|
||||
|
||||
default_args.seek()
|
||||
default_args.seek(10)
|
||||
|
||||
if not default_args.booltest():
|
||||
raise RuntimeError("booltest failed")
|
||||
|
||||
if default_args.slightly_off_square(10) != 102:
|
||||
raise RuntimeError
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue