summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-04-22 15:13:02 (GMT)
committerGitHub <noreply@github.com>2023-04-22 15:13:02 (GMT)
commitb2fdae9d86cd91fc75ca6a91f772cf805d536f42 (patch)
tree3fcfb845fcc810b82531a6e45a0ddff3308180b0 /Lib/inspect.py
parent2b5dbd1f237a013defdaf0799e0a1a3cbd0b13cc (diff)
downloadcpython-b2fdae9d86cd91fc75ca6a91f772cf805d536f42.zip
cpython-b2fdae9d86cd91fc75ca6a91f772cf805d536f42.tar.gz
cpython-b2fdae9d86cd91fc75ca6a91f772cf805d536f42.tar.bz2
[3.11] gh-103556: [inspect.Signature] disallow pos-or-kw params without default after pos-only with default (GH-103557) (#103675)
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index bc49e68..75d33f2 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -2978,7 +2978,7 @@ class Signature:
if __validate_parameters__:
params = OrderedDict()
top_kind = _POSITIONAL_ONLY
- kind_defaults = False
+ seen_default = False
for param in parameters:
kind = param.kind
@@ -2993,21 +2993,19 @@ class Signature:
kind.description)
raise ValueError(msg)
elif kind > top_kind:
- kind_defaults = False
top_kind = kind
if kind in (_POSITIONAL_ONLY, _POSITIONAL_OR_KEYWORD):
if param.default is _empty:
- if kind_defaults:
+ if seen_default:
# No default for this parameter, but the
- # previous parameter of the same kind had
- # a default
+ # previous parameter of had a default
msg = 'non-default argument follows default ' \
'argument'
raise ValueError(msg)
else:
# There is a default for this parameter.
- kind_defaults = True
+ seen_default = True
if name in params:
msg = 'duplicate parameter name: {!r}'.format(name)