Skip to content

Commit f98d75e

Browse files
authored
[conformance suite] Update an assertion in historical_positional.py to allow an optional error (#2167)
The comment immediately above the `f3` definition states: ```py # > Consistent with PEP 570 syntax, positional-only parameters cannot appear # > after parameters that accept keyword arguments. Type checkers should # > enforce this requirement: ``` But mandating that type checkers should permit the `f3` definition appears inconsistent with this comment. The `x` parameter of this function accepts keyword arguments, and comes before a parameter that uses the legacy convention for denoting positional-only parameters, so according to the portion of the spec quoted here I think type checkers *should* emit an error on it. This PR updates the line to allow an optional error to be emitted by type checkers (though I'd personally also be okay with mandating an error).
1 parent b73e3aa commit f98d75e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

conformance/tests/historical_positional.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,23 @@ def f1(__x: int, __y__: int = 0) -> None: ...
2626
def f2(x: int, __y: int) -> None: ... # E
2727

2828

29-
def f3(x: int, *args: int, __y: int) -> None: ... # OK
29+
# `x` is a positional-or-keyword parameter, so,
30+
# according to a literal reading of the above rule, `__y`
31+
# should be flagged as an error since it uses the historical
32+
# convention for positional-only parameters but appears after
33+
# a positional-or-keyword parameter that does not. We therefore
34+
# permit type checkers to emit an error on this definition.
35+
#
36+
# Note that `x` can only be passed with a keyword argument if
37+
# no arguments are passed positionally:
38+
#
39+
# ```pycon
40+
# >>> def f3(x: int, *args: int, __y: int) -> None: ...
41+
# ...
42+
# >>> f3(x=1, __y=2)
43+
# >>>
44+
# ```
45+
def f3(x: int, *args: int, __y: int) -> None: ... # E?
3046

3147

3248
f3(3, __y=3) # OK

0 commit comments

Comments
 (0)