Skip to content

Commit 3ea0261

Browse files
committed
type hints: Fix a few minor logic errors
Some logic in create_signature_union was incorrect, also some oversight caused a useless function call. Task-number: PYSIDE-3012 Change-Id: Id5e446679056ec68ae2868cf7ccea787f6df5629 Pick-to: 6.8 Reviewed-by: Shyamnath Premnadh <[email protected]>
1 parent 445e871 commit 3ea0261

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/layout.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def create_signature_union(props, key):
316316
del annotations["return"]
317317

318318
# Build a signature.
319-
kind = DEFAULT_PARAM_KIND
319+
kind = last = DEFAULT_PARAM_KIND
320320
params = []
321321
snake_flag = using_snake_case()
322322

@@ -339,6 +339,8 @@ def create_signature_union(props, key):
339339
if default is not _empty:
340340
if kind != _KEYWORD_ONLY:
341341
kind = _POSITIONAL_OR_KEYWORD
342+
if last == _VAR_POSITIONAL:
343+
kind = _KEYWORD_ONLY
342344
if default is None:
343345
ann = typing.Optional[ann]
344346
if default is not _empty and layout.ellipsis:
@@ -355,6 +357,7 @@ def create_signature_union(props, key):
355357
continue
356358
if snake_flag:
357359
name = make_snake_case_name(name)
360+
last = kind
358361
param = inspect.Parameter(name, kind, annotation=ann, default=default)
359362
params.append(param)
360363

@@ -374,15 +377,11 @@ def transform(signature):
374377
if typing.get_origin(ann) is typing.Union:
375378
args = typing.get_args(ann)
376379
ann = reduce(operator.or_, args)
377-
new_param = param.replace(annotation=ann)
380+
param = param.replace(annotation=ann)
378381
changed = True
379-
else:
380-
new_param = param
381-
parameters.append(new_param)
382+
parameters.append(param)
382383

383-
# Create the Signature anew. Replace would not allow errors (see Signal and Slot).
384-
return inspect.Signature(parameters, return_annotation=signature.return_annotation,
385-
__validate_parameters__=False) if changed else signature
384+
return signature.replace(parameters=parameters) if changed else signature
386385

387386

388387
def create_signature(props, key):

sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/pyi_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def _function(self, func_name, signature, spaces, decorator=None, opt_comment=""
206206
# the formatting with the inspect module explicitly removes the `typing` prefix.
207207
signature = self.fix_typing_prefix(signature)
208208
# from now on, the signature will be stringized.
209-
signature = self.optional_replacer(signature)
209+
signature = self.last_fixups(signature)
210210
self.print(f'{spaces}def {func_name}{signature}: ...{opt_comment}')
211211

212212
@contextmanager

0 commit comments

Comments
 (0)