Skip to content

Commit 42a84a1

Browse files
Remove too many positional args
Fixes #30
1 parent da735b4 commit 42a84a1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

record_api/apis.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
Type = OutputType
1919

2020

21+
# If there are more than 2 optional positional only args, convert them all to variadic positional args
22+
MAX_OPTIONAL_POSITIONAL_ONLY_ARGS = 2
23+
24+
2125
def orjson_dumps(v, *, default):
2226
# orjson.dumps returns bytes, to match standard json.dumps we need to decode
2327
return orjson.dumps(v, default=default, option=orjson.OPT_INDENT_2).decode() # type: ignore
@@ -555,8 +559,29 @@ def __ior__(self, other: Signature) -> Signature:
555559
self._copy_var_kw(other)
556560

557561
update_add(self.metadata, other.metadata)
562+
self._trim_positional_only_args()
558563
return self
559564

565+
def _trim_positional_only_args(self):
566+
"""
567+
If there are excss positional only args, move them to variable positional only args
568+
"""
569+
# if we already have var pos only args, remove all positional only args
570+
if (
571+
self.var_pos
572+
or len(self.pos_only_optional) > MAX_OPTIONAL_POSITIONAL_ONLY_ARGS
573+
):
574+
var_pos_output = unify(
575+
[
576+
self.var_pos[1] if self.var_pos else BottomOutput(),
577+
*self.pos_only_optional.values(),
578+
]
579+
)
580+
var_pos_label = self.var_pos[0] if self.var_pos else "_args"
581+
self.var_pos = (var_pos_label, var_pos_output)
582+
self.pos_only_optional = {}
583+
self.pos_only_optional_ordering = []
584+
560585
def _copy_pos_only(self, other: Signature) -> None:
561586
pos_only_required = dict(
562587
map(

0 commit comments

Comments
 (0)