Skip to content

Commit

Permalink
don't special-case params named __ for historical positional params
Browse files Browse the repository at this point in the history
Summary:
https://typing.readthedocs.io/en/latest/spec/historical.html#positional-only-parameters

The rule is:

> all parameters with names that begin but don’t end with __ are assumed to be positional-only

Strictly reading the rules, `__` ends with `__` so it should not be positional only. However, Pyre special-cases `__` to count as positional. Pyright doesn't have the special case, and Mypy doesn't implement this check from what I can tell.

Reviewed By: stroxler

Differential Revision: D60151159

fbshipit-source-id: 4ccb8133d6860ae844bc4a3c7071cb4a7605d3da
  • Loading branch information
yangdanny97 authored and facebook-github-bot committed Jul 24, 2024
1 parent 7f1a3cb commit aea4c1f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions source/analysis/test/typeTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3704,8 +3704,8 @@ let test_parameter_create _ =
(Type.Callable.CallableParamType.create
[{ Type.Callable.CallableParamType.name = "__"; annotation = Type.integer; default = false }])
[
Type.Callable.CallableParamType.PositionalOnly
{ index = 0; annotation = Type.integer; default = false };
Type.Callable.CallableParamType.Named
{ name = "__"; annotation = Type.integer; default = false };
]
Expand Down
5 changes: 2 additions & 3 deletions source/analysis/type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1470,9 +1470,8 @@ module Callable = struct
if
(not keyword_only)
&& (not has_pep570_syntax)
&& (String.equal sanitized "__"
|| String.is_prefix sanitized ~prefix:"__"
&& not (String.is_suffix sanitized ~suffix:"__"))
&& String.is_prefix sanitized ~prefix:"__"
&& not (String.is_suffix sanitized ~suffix:"__")
then
index + 1, CallableParamType.PositionalOnly { index; annotation; default }
else
Expand Down
5 changes: 2 additions & 3 deletions source/interprocedural_analyses/taint/accessPath.ml
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,8 @@ let normalize_parameters parameters =
let positional_only =
(not seen_star)
&& (not has_pep570_syntax)
&& (String.equal unqualified_name "__"
|| String.is_prefix unqualified_name ~prefix:"__"
&& not (String.is_suffix unqualified_name ~suffix:"__"))
&& String.is_prefix unqualified_name ~prefix:"__"
&& not (String.is_suffix unqualified_name ~suffix:"__")
in
( position + 1,
false,
Expand Down

0 comments on commit aea4c1f

Please sign in to comment.