Commit MetaInfo

Revisiona9b6fb2f41a2a39efcb701440539361020ce7af5 (tree)
Time2022-07-24 00:17:44
AuthorAntoon Pardon <aej@pard...>
CommiterAntoon Pardon

Log Message

finishing pass_defaults

Change Summary

Incremental Difference

diff -r 0cd962ec592f -r a9b6fb2f41a2 prepare
--- a/prepare Sun Jul 17 13:30:45 2022 +0200
+++ b/prepare Sat Jul 23 17:17:44 2022 +0200
@@ -2,11 +2,11 @@
22
33 set -e
44
5-ENVIRONMENT=conda3.10
5+ENVIRONMENT=conda3
66 PYTHONPATH=$(type -p python3)
77
88 case $PYTHONPATH in
9- */$ENVIRONMENT/bin/python3)
9+ */$ENVIRONMENT*/bin/python3)
1010 ;;
1111 *)
1212 echo ""
diff -r 0cd962ec592f -r a9b6fb2f41a2 source/decorators.py
--- a/source/decorators.py Sun Jul 17 13:30:45 2022 +0200
+++ b/source/decorators.py Sat Jul 23 17:17:44 2022 +0200
@@ -43,13 +43,20 @@
4343 have the function use the default value
4444 """
4545
46+ signature = signature_of(func)
47+ parameter_items = list(signature.parameters.items())
48+
4649 @wraps(func)
47- def wrapper(*args):
48- try:
49- default_index = args.index(default)
50- newargs = args[:default_index]
51- except ValueError:
52- newargs = args
53- return func(*newargs)
50+ def wrapper(*args, **kwds):
51+ newargs = []
52+ for arg, item in zip(args, parameter_items):
53+ parameter = item[1]
54+ if arg is not default:
55+ newargs.append(arg)
56+ elif parameter.default is not Parameter.empty:
57+ newargs.append(parameter.default)
58+ else:
59+ raise ValueError('"default" used as argument when no default is available')
60+ return func(*newargs, **kwds)
5461
5562 return wrapper
diff -r 0cd962ec592f -r a9b6fb2f41a2 source/release.cfg
--- a/source/release.cfg Sun Jul 17 13:30:45 2022 +0200
+++ b/source/release.cfg Sat Jul 23 17:17:44 2022 +0200
@@ -1,3 +1,3 @@
1-version = '0.01.10k'
2-modified = '2022-07-17 @ 13:30:45'
1+version = '0.01.11e'
2+modified = '2022-07-23 @ 17:16:36'
33 installed = '*********************'
diff -r 0cd962ec592f -r a9b6fb2f41a2 tests/decorators.py
--- a/tests/decorators.py Sun Jul 17 13:30:45 2022 +0200
+++ b/tests/decorators.py Sat Jul 23 17:17:44 2022 +0200
@@ -1,4 +1,4 @@
1-#pylint: disable=invalid-name,no-self-argument,missing-function-docstring,(missing-module-docstring,dangerous-default-value)
1+#pylint: disable=invalid-name,no-self-argument,missing-function-docstring,missing-module-docstring,dangerous-default-value,unused-import
22
33 from unittest import TestCase, main as unitmain, skip
44
@@ -46,7 +46,7 @@
4646
4747 class InspectPassDefaults(TestCase):
4848 """
49- class for testing copy_defaults
49+ class for testing pass_defaults
5050 """
5151
5252 def test_no_defaults(s):
@@ -60,16 +60,18 @@
6060 s.assertEqual((3, 5, df3), multi_return(3, 5, default))
6161 s.assertEqual((3, df2, df3), multi_return(3, default, default))
6262
63+ def test_keyword_value(s):
64+ s.assertEqual((3, df2, 8), multi_return(3, p3 = 8))
65+
6366 def test_too_few_arguments(s):
6467 # pylint: disable=no-value-for-parameter
6568 with s.assertRaises(TypeError):
6669 multi_return()
6770
6871 def test_default_value_too_soon(s):
69- with s.assertRaises(TypeError):
72+ with s.assertRaises(ValueError):
7073 multi_return(default)
7174
72- @skip("This is beyond normal default behaviour")
7375 def test_default_value_in_the_middle(s):
7476 s.assertEqual((3, df2, 8), multi_return(3, default, 8))
7577
Show on old repository browser