Skip to content

Commit

Permalink
Fixed a few bugs in the constructor conformance tests that I found wh… (
Browse files Browse the repository at this point in the history
#1717)

Fixed a few bugs in the constructor conformance tests that I found when implementing the spec in pyright. Also added a few missing test cases.
  • Loading branch information
erictraut committed Apr 14, 2024
1 parent b723985 commit ba14690
Show file tree
Hide file tree
Showing 14 changed files with 280 additions and 248 deletions.
5 changes: 5 additions & 0 deletions conformance/results/mypy/constructors_call_type.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ Does not validate call to custom metaclass __call__ method through type[T].
conformance_automated = "Fail"
errors_diff = """
Line 30: Expected 1 errors
Line 72: Expected 1 errors
"""
output = """
constructors_call_type.py:40: error: Missing positional arguments "x", "y" in call to "Class2" [call-arg]
constructors_call_type.py:50: error: Missing positional arguments "x", "y" in call to "Class3" [call-arg]
constructors_call_type.py:59: error: Too many arguments for "Class4" [call-arg]
constructors_call_type.py:64: error: Too many arguments for "object" [call-arg]
constructors_call_type.py:81: error: Missing positional argument "y" in call to "Class2" [call-arg]
constructors_call_type.py:82: error: Argument 2 to "Class2" has incompatible type "int"; expected "str" [arg-type]
"""
84 changes: 40 additions & 44 deletions conformance/results/mypy/constructors_callable.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,46 @@ Does not support __new__ return type that is different from class being construc
"""
conformance_automated = "Fail"
errors_diff = """
Line 83: Expected 1 errors
Line 84: Expected 1 errors
Line 156: Expected 1 errors
Line 93: Unexpected errors ['constructors_callable.py:93: error: Incompatible return type for "__new__" (returns "int", but must return a subtype of "Class4") [misc]']
Line 102: Unexpected errors ['constructors_callable.py:102: error: Incompatible types in assignment (expression has type "Callable[[int], Class4]", variable has type "Expected4") [assignment]']
Line 103: Unexpected errors ['constructors_callable.py:103: error: Expression is of type "Class4", not "int" [assert-type]']
Line 126: Unexpected errors ['constructors_callable.py:126: error: Incompatible types in assignment (expression has type "Callable[[VarArg(Any), KwArg(Any)], Class5]", variable has type "Expected5") [assignment]']
Line 129: Unexpected errors ['constructors_callable.py:129: error: Expression is of type "Class5", not "NoReturn" [assert-type]']
Line 140: Unexpected errors ['constructors_callable.py:140: error: Incompatible return type for "__new__" (returns "Class6Proxy", but must return a subtype of "Class6") [misc]']
Line 141: Unexpected errors ['constructors_callable.py:141: error: Incompatible return value type (got "Class6", expected "Class6Proxy") [return-value]']
Line 154: Unexpected errors ['constructors_callable.py:154: error: Incompatible types in assignment (expression has type "Callable[[int], Class6]", variable has type "Expected6") [assignment]']
Line 155: Unexpected errors ['constructors_callable.py:155: error: Expression is of type "Class6", not "Class6Proxy" [assert-type]', 'constructors_callable.py:155: error: Too few arguments [call-arg]']
Line 175: Unexpected errors ['constructors_callable.py:175: error: The erased type of self "constructors_callable.Class7[builtins.int]" is not a supertype of its class "constructors_callable.Expected7" [misc]']
Line 177: Unexpected errors ['constructors_callable.py:177: error: The erased type of self "constructors_callable.Class7[builtins.str]" is not a supertype of its class "constructors_callable.Expected7" [misc]']
Line 127: Expected 1 errors
Line 144: Expected 1 errors
Line 73: Unexpected errors ['constructors_callable.py:73: error: Incompatible return type for "__new__" (returns "int", but must return a subtype of "Class4") [misc]']
Line 78: Unexpected errors ['constructors_callable.py:78: error: Expression is of type "Class4", not "int" [assert-type]']
Line 100: Unexpected errors ['constructors_callable.py:100: error: Expression is of type "Class5", not "NoReturn" [assert-type]']
Line 105: Unexpected errors ['constructors_callable.py:105: error: Expression is of type "Class5", not "NoReturn" [assert-type]']
Line 116: Unexpected errors ['constructors_callable.py:116: error: Incompatible return type for "__new__" (returns "Class6Proxy", but must return a subtype of "Class6") [misc]']
Line 117: Unexpected errors ['constructors_callable.py:117: error: Incompatible return value type (got "Class6", expected "Class6Proxy") [return-value]']
Line 126: Unexpected errors ['constructors_callable.py:126: error: Expression is of type "Class6", not "Class6Proxy" [assert-type]', 'constructors_callable.py:126: error: Too few arguments [call-arg]']
Line 143: Unexpected errors ['constructors_callable.py:143: error: Expression is of type "Class6Any", not "Any" [assert-type]', 'constructors_callable.py:143: error: Too few arguments [call-arg]']
"""
output = """
constructors_callable.py:41: note: Revealed type is "def (x: builtins.int) -> constructors_callable.Class1"
constructors_callable.py:44: error: Too few arguments [call-arg]
constructors_callable.py:58: note: Revealed type is "def () -> constructors_callable.Class2"
constructors_callable.py:61: error: Too many arguments [call-arg]
constructors_callable.py:81: note: Revealed type is "def (x: builtins.int) -> constructors_callable.Class3"
constructors_callable.py:86: error: Too few arguments [call-arg]
constructors_callable.py:87: error: Too many arguments [call-arg]
constructors_callable.py:93: error: Incompatible return type for "__new__" (returns "int", but must return a subtype of "Class4") [misc]
constructors_callable.py:101: note: Revealed type is "def (x: builtins.int) -> constructors_callable.Class4"
constructors_callable.py:102: error: Incompatible types in assignment (expression has type "Callable[[int], Class4]", variable has type "Expected4") [assignment]
constructors_callable.py:102: note: "Expected4.__call__" has type "Callable[[Arg(int, 'x')], int]"
constructors_callable.py:103: error: Expression is of type "Class4", not "int" [assert-type]
constructors_callable.py:104: error: Too few arguments [call-arg]
constructors_callable.py:125: note: Revealed type is "def (*args: Any, **kwargs: Any) -> constructors_callable.Class5"
constructors_callable.py:126: error: Incompatible types in assignment (expression has type "Callable[[VarArg(Any), KwArg(Any)], Class5]", variable has type "Expected5") [assignment]
constructors_callable.py:126: note: "Expected5.__call__" has type "Callable[[], NoReturn]"
constructors_callable.py:129: error: Expression is of type "Class5", not "NoReturn" [assert-type]
constructors_callable.py:140: error: Incompatible return type for "__new__" (returns "Class6Proxy", but must return a subtype of "Class6") [misc]
constructors_callable.py:141: error: Incompatible return value type (got "Class6", expected "Class6Proxy") [return-value]
constructors_callable.py:153: note: Revealed type is "def (x: builtins.int) -> constructors_callable.Class6"
constructors_callable.py:154: error: Incompatible types in assignment (expression has type "Callable[[int], Class6]", variable has type "Expected6") [assignment]
constructors_callable.py:154: note: "Expected6.__call__" has type "Callable[[], Class6Proxy]"
constructors_callable.py:155: error: Expression is of type "Class6", not "Class6Proxy" [assert-type]
constructors_callable.py:155: error: Too few arguments [call-arg]
constructors_callable.py:175: error: The erased type of self "constructors_callable.Class7[builtins.int]" is not a supertype of its class "constructors_callable.Expected7" [misc]
constructors_callable.py:177: error: The erased type of self "constructors_callable.Class7[builtins.str]" is not a supertype of its class "constructors_callable.Expected7" [misc]
constructors_callable.py:182: note: Revealed type is "Overload(def (x: builtins.int) -> constructors_callable.Class7[builtins.int], def (x: builtins.str) -> constructors_callable.Class7[builtins.str])"
constructors_callable.py:203: note: Revealed type is "def [T] (x: T`1, y: builtins.list[T`1]) -> constructors_callable.Class8[T`1]"
constructors_callable.py:213: note: Revealed type is "def [T] (x: builtins.list[T`-1], y: builtins.list[T`-1]) -> constructors_callable.Class9"
constructors_callable.py:215: error: Cannot infer function type argument [misc]
constructors_callable.py:36: note: Revealed type is "def (x: builtins.int) -> constructors_callable.Class1"
constructors_callable.py:38: error: Too few arguments [call-arg]
constructors_callable.py:39: error: Unexpected keyword argument "y" [call-arg]
constructors_callable.py:49: note: Revealed type is "def () -> constructors_callable.Class2"
constructors_callable.py:51: error: Too many arguments [call-arg]
constructors_callable.py:63: note: Revealed type is "def (x: builtins.int) -> constructors_callable.Class3"
constructors_callable.py:65: error: Too few arguments [call-arg]
constructors_callable.py:66: error: Unexpected keyword argument "y" [call-arg]
constructors_callable.py:67: error: Too many arguments [call-arg]
constructors_callable.py:73: error: Incompatible return type for "__new__" (returns "int", but must return a subtype of "Class4") [misc]
constructors_callable.py:77: note: Revealed type is "def (x: builtins.int) -> constructors_callable.Class4"
constructors_callable.py:78: error: Expression is of type "Class4", not "int" [assert-type]
constructors_callable.py:79: error: Too few arguments [call-arg]
constructors_callable.py:80: error: Unexpected keyword argument "y" [call-arg]
constructors_callable.py:97: note: Revealed type is "def (*args: Any, **kwargs: Any) -> constructors_callable.Class5"
constructors_callable.py:100: error: Expression is of type "Class5", not "NoReturn" [assert-type]
constructors_callable.py:105: error: Expression is of type "Class5", not "NoReturn" [assert-type]
constructors_callable.py:116: error: Incompatible return type for "__new__" (returns "Class6Proxy", but must return a subtype of "Class6") [misc]
constructors_callable.py:117: error: Incompatible return value type (got "Class6", expected "Class6Proxy") [return-value]
constructors_callable.py:125: note: Revealed type is "def (x: builtins.int) -> constructors_callable.Class6"
constructors_callable.py:126: error: Expression is of type "Class6", not "Class6Proxy" [assert-type]
constructors_callable.py:126: error: Too few arguments [call-arg]
constructors_callable.py:142: note: Revealed type is "def (x: builtins.int) -> constructors_callable.Class6Any"
constructors_callable.py:143: error: Expression is of type "Class6Any", not "Any" [assert-type]
constructors_callable.py:143: error: Too few arguments [call-arg]
constructors_callable.py:162: note: Revealed type is "Overload(def (x: builtins.int) -> constructors_callable.Class7[builtins.int], def (x: builtins.str) -> constructors_callable.Class7[builtins.str])"
constructors_callable.py:182: note: Revealed type is "def [T] (x: builtins.list[T`1], y: builtins.list[T`1]) -> constructors_callable.Class8[T`1]"
constructors_callable.py:184: error: Cannot infer function type argument [misc]
constructors_callable.py:193: note: Revealed type is "def [T] (x: builtins.list[T`-1], y: builtins.list[T`-1]) -> constructors_callable.Class9"
constructors_callable.py:195: error: Cannot infer function type argument [misc]
"""
2 changes: 1 addition & 1 deletion conformance/results/mypy/version.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = "mypy 1.9.0"
test_duration = 1.7
test_duration = 2.3
5 changes: 5 additions & 0 deletions conformance/results/pyre/constructors_call_type.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ output = """
constructors_call_type.py:30:4 Missing argument [20]: Call `Meta1.__call__` expects argument `x`.
constructors_call_type.py:40:4 Missing argument [20]: Call `Class2.__new__` expects argument `x`.
constructors_call_type.py:50:4 Missing argument [20]: Call `Class3.__init__` expects argument `x`.
constructors_call_type.py:59:4 Too many arguments [19]: Call `object.__init__` expects 0 positional arguments, 1 was provided.
constructors_call_type.py:64:4 Too many arguments [19]: Call `object.__init__` expects 0 positional arguments, 1 was provided.
constructors_call_type.py:72:4 Missing argument [20]: Call `Meta1.__call__` expects argument `x`.
constructors_call_type.py:81:4 Missing argument [20]: Call `Class2.__new__` expects argument `y`.
constructors_call_type.py:82:11 Incompatible parameter type [6]: In call `Class2.__new__`, for 2nd positional argument, expected `str` but got `int`.
"""

0 comments on commit ba14690

Please sign in to comment.