py2api 0.0.4__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {py2api-0.0.4 → py2api-0.0.6}/PKG-INFO +2 -2
  2. {py2api-0.0.4 → py2api-0.0.6}/py2api/py2rest/input_trans.py +2 -1
  3. py2api-0.0.6/py2api/tests/test_input_trans_else.py +21 -0
  4. {py2api-0.0.4 → py2api-0.0.6}/py2api/util.py +15 -3
  5. {py2api-0.0.4 → py2api-0.0.6}/pyproject.toml +1 -1
  6. {py2api-0.0.4 → py2api-0.0.6}/.editorconfig +0 -0
  7. {py2api-0.0.4 → py2api-0.0.6}/.github/workflows/ci.yml +0 -0
  8. {py2api-0.0.4 → py2api-0.0.6}/.gitignore +0 -0
  9. {py2api-0.0.4 → py2api-0.0.6}/.idea/inspectionProfiles/profiles_settings.xml +0 -0
  10. {py2api-0.0.4 → py2api-0.0.6}/.idea/misc.xml +0 -0
  11. {py2api-0.0.4 → py2api-0.0.6}/.idea/modules.xml +0 -0
  12. {py2api-0.0.4 → py2api-0.0.6}/.idea/py2api.iml +0 -0
  13. {py2api-0.0.4 → py2api-0.0.6}/.idea/vcs.xml +0 -0
  14. {py2api-0.0.4 → py2api-0.0.6}/.idea/workspace.xml +0 -0
  15. {py2api-0.0.4 → py2api-0.0.6}/LICENSE +0 -0
  16. {py2api-0.0.4 → py2api-0.0.6}/README.md +0 -0
  17. {py2api-0.0.4 → py2api-0.0.6}/docsrc/.gitignore +0 -0
  18. {py2api-0.0.4 → py2api-0.0.6}/docsrc/Makefile +0 -0
  19. {py2api-0.0.4 → py2api-0.0.6}/docsrc/conf.py +0 -0
  20. {py2api-0.0.4 → py2api-0.0.6}/docsrc/index.rst +0 -0
  21. {py2api-0.0.4 → py2api-0.0.6}/docsrc/make.bat +0 -0
  22. {py2api-0.0.4 → py2api-0.0.6}/py2api/.gitignore +0 -0
  23. {py2api-0.0.4 → py2api-0.0.6}/py2api/__init__.py +0 -0
  24. {py2api-0.0.4 → py2api-0.0.6}/py2api/constants.py +0 -0
  25. {py2api-0.0.4 → py2api-0.0.6}/py2api/defaults.py +0 -0
  26. {py2api-0.0.4 → py2api-0.0.6}/py2api/errors.py +0 -0
  27. {py2api-0.0.4 → py2api-0.0.6}/py2api/examples/__init__.py +0 -0
  28. {py2api-0.0.4 → py2api-0.0.6}/py2api/examples/pong.py +0 -0
  29. {py2api-0.0.4 → py2api-0.0.6}/py2api/examples/streaming_sine.py +0 -0
  30. {py2api-0.0.4 → py2api-0.0.6}/py2api/examples/wrapping_a_class.py +0 -0
  31. {py2api-0.0.4 → py2api-0.0.6}/py2api/examples/wrapping_a_module.py +0 -0
  32. {py2api-0.0.4 → py2api-0.0.6}/py2api/obj_wrap.py +0 -0
  33. {py2api-0.0.4 → py2api-0.0.6}/py2api/output_trans.py +0 -0
  34. {py2api-0.0.4 → py2api-0.0.6}/py2api/py2rest/__init__.py +0 -0
  35. {py2api-0.0.4 → py2api-0.0.6}/py2api/py2rest/app_maker.py +0 -0
  36. {py2api-0.0.4 → py2api-0.0.6}/py2api/py2rest/constants.py +0 -0
  37. {py2api-0.0.4 → py2api-0.0.6}/py2api/py2rest/obj_wrap.py +0 -0
  38. {py2api-0.0.4 → py2api-0.0.6}/py2api/py2rest/old/old_input_trans_with_val_type.py +0 -0
  39. {py2api-0.0.4 → py2api-0.0.6}/py2api/py2rest/rest2py.py +0 -0
  40. {py2api-0.0.4 → py2api-0.0.6}/py2api/scrap_obj_wrap.py +0 -0
  41. {py2api-0.0.4 → py2api-0.0.6}/py2api/tests/wrapping_a_class.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: py2api
3
- Version: 0.0.4
3
+ Version: 0.0.6
4
4
  Summary: Declarative API entry point
5
5
  Project-URL: Homepage, https://github.com/thorwhalen/py2api
6
6
  Author: Thor Whalen
@@ -304,8 +304,9 @@ class InputTrans:
304
304
  # return trans_func
305
305
 
306
306
  ############### _ELSE ###############
307
+ # Only a fallback: a match found above (source, attr or argname) wins.
307
308
  _trans_spec = trans_spec.get(_ELSE, TRANS_NOT_FOUND)
308
- if _trans_spec:
309
+ if trans_func is TRANS_NOT_FOUND and _trans_spec:
309
310
  trans_func = self.search_trans_func(
310
311
  attr, argname, val, trans_spec=_trans_spec, source=source
311
312
  )
@@ -0,0 +1,21 @@
1
+ """``_ELSE`` is a fallback: a more specific match must win over it."""
2
+
3
+ import json
4
+
5
+ from py2api.constants import _ARGNAME, _ELSE
6
+ from py2api.py2rest.input_trans import InputTrans
7
+
8
+ SPEC = {_ARGNAME: {"index": int, "source": str}, _ELSE: json.loads}
9
+
10
+
11
+ def _found(argname):
12
+ return InputTrans(trans_spec=SPEC).search_trans_func(None, argname, "val", SPEC)
13
+
14
+
15
+ def test_a_matching_argname_beats_else():
16
+ assert _found("source") is str
17
+ assert _found("index") is int
18
+
19
+
20
+ def test_else_applies_when_nothing_else_matches():
21
+ assert _found("other") is json.loads
@@ -45,7 +45,15 @@ def enhanced_docstr(func):
45
45
  >>> print(enhanced_docstr(foo))
46
46
  foo(a, b=3, c="as", d=SomeClass, dd=some_function, ddd=None, *args, **kwargs)
47
47
  some documentation...
48
- >>>
48
+
49
+ A function with no default arguments keeps all of its positional args
50
+ (regression: ``args[:-len(dflts)]`` used to drop them all when ``dflts`` was empty):
51
+
52
+ >>> def no_defaults(a, b, c):
53
+ ... '''some docs'''
54
+ >>> print(enhanced_docstr(no_defaults))
55
+ no_defaults(a, b, c)
56
+ some docs
49
57
  """
50
58
  argspec = getfullargspec(func)
51
59
 
@@ -53,9 +61,13 @@ def enhanced_docstr(func):
53
61
  dflts = list(map(_strigify_val, dflts))
54
62
 
55
63
  args_strings = list()
56
- args_strings += argspec.args[: -len(dflts)]
64
+ # Number of positional (non-default) args. Computed as a length so that the
65
+ # no-defaults case works: with len(dflts)==0, args[:-0] would wrongly be []
66
+ # (since -0 == 0), dropping every positional arg.
67
+ n_positional = len(argspec.args) - len(dflts)
68
+ args_strings += argspec.args[:n_positional]
57
69
  args_strings += [
58
- "{}={}".format(*x) for x in zip(argspec.args[-len(dflts) :], dflts)
70
+ "{}={}".format(*x) for x in zip(argspec.args[n_positional:], dflts)
59
71
  ]
60
72
  if argspec.varargs is not None:
61
73
  args_strings += [f"*{argspec.varargs}"]
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
 
7
7
  [project]
8
8
  name = "py2api"
9
- version = "0.0.4"
9
+ version = "0.0.6"
10
10
  description = "Declarative API entry point"
11
11
  readme = "README.md"
12
12
  requires-python = ">=3.10"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes