From aea4c1fce853eeb802fbdc9a4d5c18e0ca324ac4 Mon Sep 17 00:00:00 2001 From: Danny Yang Date: Wed, 24 Jul 2024 13:17:21 -0700 Subject: [PATCH] don't special-case params named __ for historical positional params MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- source/analysis/test/typeTest.ml | 4 ++-- source/analysis/type.ml | 5 ++--- source/interprocedural_analyses/taint/accessPath.ml | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/source/analysis/test/typeTest.ml b/source/analysis/test/typeTest.ml index 13c339d6108..7e877c01864 100644 --- a/source/analysis/test/typeTest.ml +++ b/source/analysis/test/typeTest.ml @@ -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 }; ] diff --git a/source/analysis/type.ml b/source/analysis/type.ml index ee503d15d43..b226f367c2c 100644 --- a/source/analysis/type.ml +++ b/source/analysis/type.ml @@ -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 diff --git a/source/interprocedural_analyses/taint/accessPath.ml b/source/interprocedural_analyses/taint/accessPath.ml index 90eb2271bf7..0563da69483 100644 --- a/source/interprocedural_analyses/taint/accessPath.ml +++ b/source/interprocedural_analyses/taint/accessPath.ml @@ -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,