Skip to content

Commit 6c964dd

Browse files
authored
(🎁) conformance: NewType isn't a class (#2015)
* conformance: `NewType` isn't a class * conformance: update results
1 parent d4263de commit 6c964dd

10 files changed

+62
-45
lines changed
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
`NewType`s are considered classes, not functions.
4+
"""
25
output = """
36
aliases_newtype.py:11: error: Argument 1 to "UserId" has incompatible type "str"; expected "int" [arg-type]
47
aliases_newtype.py:12: error: Incompatible types in assignment (expression has type "int", variable has type "UserId") [assignment]
5-
aliases_newtype.py:20: error: Cannot use isinstance() with NewType type [misc]
6-
aliases_newtype.py:23: error: Cannot subclass "NewType" [misc]
7-
aliases_newtype.py:32: error: String argument 1 "BadName" to NewType(...) does not match variable name "GoodName" [misc]
8-
aliases_newtype.py:38: error: "GoodNewType1" expects no type arguments, but 1 given [type-arg]
9-
aliases_newtype.py:44: error: Argument 2 to NewType(...) must be subclassable (got "int | str") [valid-newtype]
10-
aliases_newtype.py:47: error: Type variable "aliases_newtype.T" is unbound [valid-type]
11-
aliases_newtype.py:47: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class)
12-
aliases_newtype.py:47: note: (Hint: Use "T" in function signature to bind "T" inside a function)
13-
aliases_newtype.py:49: error: NewType cannot be used with protocol classes [misc]
14-
aliases_newtype.py:51: error: Argument 2 to NewType(...) must be subclassable (got "Literal[7]") [valid-newtype]
15-
aliases_newtype.py:58: error: Argument 2 to NewType(...) must be subclassable (got "TD1") [valid-newtype]
16-
aliases_newtype.py:60: error: NewType(...) expects exactly two positional arguments [misc]
17-
aliases_newtype.py:62: error: Argument 2 to NewType(...) must be subclassable (got "Any") [valid-newtype]
8+
aliases_newtype.py:23: error: Cannot use isinstance() with NewType type [misc]
9+
aliases_newtype.py:26: error: Cannot subclass "NewType" [misc]
10+
aliases_newtype.py:35: error: String argument 1 "BadName" to NewType(...) does not match variable name "GoodName" [misc]
11+
aliases_newtype.py:41: error: "GoodNewType1" expects no type arguments, but 1 given [type-arg]
12+
aliases_newtype.py:47: error: Argument 2 to NewType(...) must be subclassable (got "int | str") [valid-newtype]
13+
aliases_newtype.py:50: error: Type variable "aliases_newtype.T" is unbound [valid-type]
14+
aliases_newtype.py:50: note: (Hint: Use "Generic[T]" or "Protocol[T]" base class to bind "T" inside a class)
15+
aliases_newtype.py:50: note: (Hint: Use "T" in function signature to bind "T" inside a function)
16+
aliases_newtype.py:52: error: NewType cannot be used with protocol classes [misc]
17+
aliases_newtype.py:54: error: Argument 2 to NewType(...) must be subclassable (got "Literal[7]") [valid-newtype]
18+
aliases_newtype.py:61: error: Argument 2 to NewType(...) must be subclassable (got "TD1") [valid-newtype]
19+
aliases_newtype.py:63: error: NewType(...) expects exactly two positional arguments [misc]
20+
aliases_newtype.py:65: error: Argument 2 to NewType(...) must be subclassable (got "Any") [valid-newtype]
1821
"""
19-
conformance_automated = "Pass"
22+
conformance_automated = "Fail"
2023
errors_diff = """
24+
Line 18: Expected 1 errors
2125
"""

conformance/results/mypy/version.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
version = "mypy 1.15.0"
2-
test_duration = 1.5
2+
test_duration = 1.4
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
`NewType`s are considered classes, not functions.
4+
"""
25
output = """
36
aliases_newtype.py:11:8 - error: Argument of type "Literal['user']" cannot be assigned to parameter "_x" of type "int" in function "__init__"
47
  "Literal['user']" is not assignable to "int" (reportArgumentType)
58
aliases_newtype.py:12:14 - error: Type "Literal[42]" is not assignable to declared type "UserId"
69
  "Literal[42]" is not assignable to "UserId" (reportAssignmentType)
7-
aliases_newtype.py:20:16 - error: Second argument to "isinstance" must be a class or tuple of classes
10+
aliases_newtype.py:23:16 - error: Second argument to "isinstance" must be a class or tuple of classes
811
  Class created with NewType cannot be used with instance and class checks (reportArgumentType)
9-
aliases_newtype.py:23:21 - error: Base class "UserId" is marked final and cannot be subclassed (reportGeneralTypeIssues)
10-
aliases_newtype.py:32:1 - error: NewType must be assigned to a variable with the same name (reportGeneralTypeIssues)
11-
aliases_newtype.py:38:19 - error: Expected no type arguments for class "GoodNewType1" (reportInvalidTypeArguments)
12-
aliases_newtype.py:44:38 - error: Expected class as second argument to NewType (reportGeneralTypeIssues)
13-
aliases_newtype.py:47:43 - error: Type variable "T" has no meaning in this context (reportGeneralTypeIssues)
14-
aliases_newtype.py:49:38 - error: NewType cannot be used with structural type (a Protocol or TypedDict class) (reportGeneralTypeIssues)
15-
aliases_newtype.py:51:38 - error: NewType cannot be used with Literal type (reportGeneralTypeIssues)
16-
aliases_newtype.py:58:38 - error: NewType cannot be used with structural type (a Protocol or TypedDict class) (reportGeneralTypeIssues)
17-
aliases_newtype.py:60:15 - error: NewType requires two positional arguments (reportCallIssue)
18-
aliases_newtype.py:62:38 - error: The second argument to NewType must be a known class, not Any or Unknown (reportGeneralTypeIssues)
12+
aliases_newtype.py:26:21 - error: Base class "UserId" is marked final and cannot be subclassed (reportGeneralTypeIssues)
13+
aliases_newtype.py:35:1 - error: NewType must be assigned to a variable with the same name (reportGeneralTypeIssues)
14+
aliases_newtype.py:41:19 - error: Expected no type arguments for class "GoodNewType1" (reportInvalidTypeArguments)
15+
aliases_newtype.py:47:38 - error: Expected class as second argument to NewType (reportGeneralTypeIssues)
16+
aliases_newtype.py:50:43 - error: Type variable "T" has no meaning in this context (reportGeneralTypeIssues)
17+
aliases_newtype.py:52:38 - error: NewType cannot be used with structural type (a Protocol or TypedDict class) (reportGeneralTypeIssues)
18+
aliases_newtype.py:54:38 - error: NewType cannot be used with Literal type (reportGeneralTypeIssues)
19+
aliases_newtype.py:61:38 - error: NewType cannot be used with structural type (a Protocol or TypedDict class) (reportGeneralTypeIssues)
20+
aliases_newtype.py:63:15 - error: NewType requires two positional arguments (reportCallIssue)
21+
aliases_newtype.py:65:38 - error: The second argument to NewType must be a known class, not Any or Unknown (reportGeneralTypeIssues)
1922
"""
20-
conformance_automated = "Pass"
23+
conformance_automated = "Fail"
2124
errors_diff = """
25+
Line 18: Expected 1 errors
2226
"""

conformance/results/pyright/aliases_typealiastype.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ aliases_typealiastype.py:61:42 - error: Expected class but received "Literal[Tru
3131
aliases_typealiastype.py:62:42 - error: Expected class but received "Literal[1]" (reportGeneralTypeIssues)
3232
aliases_typealiastype.py:63:42 - error: Binary operator not allowed in type expression (reportInvalidTypeForm)
3333
aliases_typealiastype.py:64:42 - error: Type expressions cannot use format string literals (f-strings) (reportGeneralTypeIssues)
34+
aliases_typealiastype.py:66:47 - error: "BadAlias21" is not defined (reportUndefinedVariable)
3435
"""
35-
conformance_automated = "Fail"
36+
conformance_automated = "Pass"
3637
errors_diff = """
37-
Line 66: Expected 1 errors
3838
"""

conformance/results/pyright/callables_protocol.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ callables_protocol.py:70:7 - error: Type "(**b: str) -> None" is not assignable
3232
  Type "(**b: str) -> None" is not assignable to type "(*vals: bytes, **kwargs: str) -> None"
3333
    Parameter "*vals" has no corresponding parameter (reportAssignmentType)
3434
callables_protocol.py:97:16 - error: Type "(x: int) -> None" is not assignable to declared type "Proto4"
35-
  "function" is incompatible with protocol "Proto4"
36-
    "other_attribute" is not present
37-
    "__call__" is not present (reportAssignmentType)
35+
  "FunctionType" is incompatible with protocol "Proto4"
36+
    "other_attribute" is not present (reportAssignmentType)
3837
callables_protocol.py:121:18 - error: Type "(*vals: bytes, max_len: int | None = None) -> list[bytes]" is not assignable to declared type "NotProto6"
39-
  "function" is not assignable to "NotProto6" (reportAssignmentType)
38+
  "FunctionType" is not assignable to "NotProto6" (reportAssignmentType)
4039
callables_protocol.py:169:7 - error: Type "(x: int) -> Any" is not assignable to declared type "Proto8"
4140
  One or more overloads of "__call__" is not assignable
4241
    Type "(x: int) -> Any" is not assignable to type "(x: str) -> str"

conformance/results/pyright/generics_syntax_infer_variance.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ generics_syntax_infer_variance.py:29:35 - error: Type "ShouldBeCovariant1[float]
66
  "ShouldBeCovariant1[float]" is not assignable to "ShouldBeCovariant1[int]"
77
    Type parameter "T@ShouldBeCovariant1" is covariant, but "float" is not a subtype of "int"
88
      "float" is not assignable to "int" (reportAssignmentType)
9+
generics_syntax_infer_variance.py:36:37 - error: Cannot instantiate abstract class "ShouldBeCovariant2"
10+
  "Collection.__len__" is not implemented
11+
  "Sequence.__getitem__" is not implemented (reportAbstractUsage)
12+
generics_syntax_infer_variance.py:37:35 - error: Cannot instantiate abstract class "ShouldBeCovariant2"
13+
  "Collection.__len__" is not implemented
14+
  "Sequence.__getitem__" is not implemented (reportAbstractUsage)
915
generics_syntax_infer_variance.py:37:35 - error: Type "ShouldBeCovariant2[float]" is not assignable to declared type "ShouldBeCovariant2[int]"
1016
  "ShouldBeCovariant2[float]" is not assignable to "ShouldBeCovariant2[int]"
1117
    Type parameter "T@ShouldBeCovariant2" is covariant, but "float" is not a subtype of "int"
@@ -57,6 +63,7 @@ generics_syntax_infer_variance.py:155:45 - error: Type "ShouldBeContravariant1[i
5763
    Type parameter "T@ShouldBeContravariant1" is contravariant, but "int" is not a supertype of "float"
5864
      "float" is not assignable to "int" (reportAssignmentType)
5965
"""
60-
conformance_automated = "Pass"
66+
conformance_automated = "Fail"
6167
errors_diff = """
68+
Line 36: Unexpected errors ['generics_syntax_infer_variance.py:36:37 - error: Cannot instantiate abstract class "ShouldBeCovariant2"']
6269
"""

conformance/results/pyright/protocols_definition.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protocols_definition.py:160:22 - error: Type "Concrete3_Bad5" is not assignable
4646
protocols_definition.py:218:22 - error: Type "Concrete4_Bad1" is not assignable to declared type "Template4"
4747
  "Concrete4_Bad1" is incompatible with protocol "Template4"
4848
    "val1" is an incompatible type
49-
      "function" is not assignable to "Sequence[float]" (reportAssignmentType)
49+
      "FunctionType" is not assignable to "Sequence[float]" (reportAssignmentType)
5050
protocols_definition.py:219:22 - error: Type "Concrete4_Bad2" is not assignable to declared type "Template4"
5151
  "Concrete4_Bad2" is incompatible with protocol "Template4"
5252
    "val1" is not present (reportAssignmentType)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version = "pyright 1.1.400"
2-
test_duration = 1.1
1+
version = "pyright 1.1.401"
2+
test_duration = 1.0

conformance/results/results.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ <h3>Python Type System Conformance Test Results</h3>
159159
<div class="table_container"><table><tbody>
160160
<tr><th class="col1">&nbsp;</th>
161161
<th class='tc-header'><div class='tc-name'>mypy 1.15.0</div>
162-
<div class='tc-time'>1.5sec</div>
162+
<div class='tc-time'>1.4sec</div>
163163
</th>
164-
<th class='tc-header'><div class='tc-name'>pyright 1.1.400</div>
165-
<div class='tc-time'>1.1sec</div>
164+
<th class='tc-header'><div class='tc-name'>pyright 1.1.401</div>
165+
<div class='tc-time'>1.0sec</div>
166166
</th>
167167
<th class='tc-header'><div class='tc-name'>pyre 0.9.23</div>
168-
<div class='tc-time'>10.7sec</div>
168+
<div class='tc-time'>0.6sec</div>
169169
</th>
170170
</tr>
171171
<tr><th class="column" colspan="4">
@@ -422,8 +422,8 @@ <h3>Python Type System Conformance Test Results</h3>
422422
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Incorrectly reports error for type alias defined with ParamSpec.</p><p>Incorrectly rejects some valid type aliases when used in annotations.</p><p>Incorrectly evaluates generic type alias with ParamSpec with missing type argument.</p><p>Does not report invalid specialization of generic type aliases.</p><p>Does not report error for attempt to instantiate union type alias.</p><p>Does not report invalid specialization of already-specialized generic type alias.</p></span></div></th>
423423
</tr>
424424
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aliases_newtype</th>
425-
<th class="column col2 conformant">Pass</th>
426-
<th class="column col2 conformant">Pass</th>
425+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>`NewType`s are considered classes, not functions.</p></span></div></th>
426+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>`NewType`s are considered classes, not functions.</p></span></div></th>
427427
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject use of NewType in `isinstance` call.</p><p>Does not reject use of NewType in class definition statement.</p><p>Does not report inconsistency between name of NewType and assigned identifier name.</p><p>Does not reject use of NewType with generic class with TypeVar.</p><p>Does not reject use of NewType with protocol class.</p><p>Does not reject use of NewType with TypedDict class.</p><p>Does not reject use of NewType with Any.</p></span></div></th>
428428
</tr>
429429
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aliases_recursive</th>

conformance/tests/aliases_newtype.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
assert_type(UserId(5) + 1, int)
1616

17+
# > NewType('Derived', Base) returns a dummy function
18+
_: type = UserId # E: functions are not instances of `type`
19+
1720
# > Both isinstance and issubclass, as well as subclassing will fail for
1821
# > NewType('Derived', Base) since function objects don’t support these
1922
# > operations.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy