From ec16e435eb296097742038dd94af2bd0a359792e Mon Sep 17 00:00:00 2001 From: Jia Chen Date: Sat, 4 May 2019 19:00:47 -0700 Subject: [PATCH] Use dunder parameter name in `Container.__contains__` (#2953) According to Ivan, PEP 544 intentionally did not specify whether method conformance check in protocol inference should look at parameter names. For example, it's up to the type checker to decide whether a class with method defined as `def foo(self, x: int)` would implement a protocol with method `def foo(self, y: int)`. Mypy decided to ignore parameter names altogether, but we Pyre team decided to be more strict and refuse to match different parameter names (as it is unsound to do so when those methods are invoked with named parameters). Since we rely on the typeshed stubs, we want to make sure at least the important stubs on typeshed conform to our standard. This PR changes `Container.__contains__` to use dunder (i.e. positional-only) parameter name specified in PEP484. This change should not affect mypy since it ignores parameter names, but will make Pyre happy as it eliminate the naming requirement for all classes that want to conform to the `Container` protocol. --- stdlib/3/typing.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index d10ac61c4..04579dd68 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -235,7 +235,7 @@ if sys.version_info >= (3, 6): @runtime class Container(Protocol[_T_co]): @abstractmethod - def __contains__(self, x: object) -> bool: ... + def __contains__(self, __x: object) -> bool: ... if sys.version_info >= (3, 6):