crates/ty_python_semantic/resources/lint_docs/invalid-legacy-positional-parameter.md
Checks for parameters that appear to be attempting to use the legacy convention to specify that a parameter is positional-only, but do so incorrectly.
The "legacy convention" for specifying positional-only parameters was
specified in PEP 484. It states that parameters with names starting with
__ should be considered positional-only by type checkers. PEP 570, introduced
in Python 3.8, added dedicated syntax for specifying positional-only parameters,
rendering the legacy convention obsolete. However, some codebases may still
use the legacy convention for compatibility with older Python versions.
In most cases, a type checker will not consider a parameter to be positional-only
if it comes after a positional-or-keyword parameter, even if its name starts with
__. This may be unexpected to the author of the code.
# `__y` is not considered positional-only
def f(x, __y): # error
pass
Use instead:
def f(__x, __y): # If you need compatibility with Python <=3.7
pass
or:
def f(x, y, /): # Python 3.8+ syntax
pass