2Tests the historical (pre-3.8) mechanism for specifying positional-only
3parameters in function signatures.
6# Specification: https://typing.readthedocs.io/en/latest/spec/historical.html#positional-only-parameters
9# > Type checkers should support the following special case: all parameters with
10# > names that begin but don’t end with __ are assumed to be positional-only:
13def f1(__x: int, __y__: int = 0) -> None: ...
[positional-only-parameter-as-kwarg] Positional-only parameter 1 (`__x`) passed as keyword argument of function `f1`
21# > Consistent with PEP 570 syntax, positional-only parameters cannot appear
22# > after parameters that accept keyword arguments. Type checkers should
23# > enforce this requirement:
26def f2(x: int, __y: int) -> None: ... # E
[invalid-legacy-positional-parameter] Invalid use of the legacy convention for positional-only parameters: Parameter name begins with `__` but will not be treated as positional-only
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.
36# Note that `x` can only be passed with a keyword argument if
37# no arguments are passed positionally:
40# >>> def f3(x: int, *args: int, __y: int) -> None: ...
45def f3(x: int, *args: int, __y: int) -> None: ... # E?
[invalid-legacy-positional-parameter] Invalid use of the legacy convention for positional-only parameters: Parameter name begins with `__` but will not be treated as positional-only
52 def m1(self, __x: int, __y__: int = 0) -> None: ...
54 def m2(self, x: int, __y: int) -> None: ... # E
[invalid-legacy-positional-parameter] Invalid use of the legacy convention for positional-only parameters: Parameter name begins with `__` but will not be treated as positional-only
[positional-only-parameter-as-kwarg] Positional-only parameter 2 (`__x`) passed as keyword argument of bound method `m1`
62# The historical mechanism should not apply when new-style (PEP 570)
66def f4(x: int, /, __y: int) -> None: ... # OK