File tree Expand file tree Collapse file tree 3 files changed +13
-9
lines changed
Filter options
Expand file tree Collapse file tree 3 files changed +13
-9
lines changed
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ from typing import (
8
8
List ,
9
9
Mapping ,
10
10
Optional ,
11
+ Protocol ,
11
12
Sequence ,
12
13
Tuple ,
13
14
Type ,
@@ -26,8 +27,6 @@ from ._cmp import cmp_using as cmp_using
26
27
from ._version_info import VersionInfo
27
28
from ._typing_compat import AttrsInstance_
28
29
29
- AttrsInstance = AttrsInstance_
30
-
31
30
if sys .version_info >= (3 , 10 ):
32
31
from typing import TypeGuard
33
32
else :
@@ -65,6 +64,10 @@ _FieldTransformer = Callable[
65
64
# _ValidatorType from working when passed in a list or tuple.
66
65
_ValidatorArgType = Union [_ValidatorType [_T ], Sequence [_ValidatorType [_T ]]]
67
66
67
+ # We subclass this here to keep the protocol's qualified name clean.
68
+ class AttrsInstance (AttrsInstance_ , Protocol ):
69
+ pass
70
+
68
71
# _make --
69
72
70
73
NOTHING : object
Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ from typing import Any, ClassVar, Protocol
2
2
3
3
MYPY = False
4
4
5
- # A protocol to be able to statically accept an attrs class.
6
- class AttrsInstance (Protocol ):
7
- __attrs_attrs__ : ClassVar [Any ]
8
-
9
5
if MYPY :
10
- AttrsInstance_ = AttrsInstance
6
+ # A protocol to be able to statically accept an attrs class.
7
+ class AttrsInstance_ (Protocol ):
8
+ __attrs_attrs__ : ClassVar [Any ]
9
+
11
10
else :
12
- AttrsInstance_ = Any
11
+ class AttrsInstance_ (Protocol ):
12
+ pass
Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ def test_pyright_attrsinstance_is_any(tmp_path):
91
91
"""\
92
92
import attrs
93
93
94
+ foo: attrs.AttrsInstance = object() # We can assign any old object to `AttrsInstance`.
94
95
reveal_type(attrs.AttrsInstance)
95
96
"""
96
97
)
@@ -99,7 +100,7 @@ def test_pyright_attrsinstance_is_any(tmp_path):
99
100
expected_diagnostics = {
100
101
PyrightDiagnostic (
101
102
severity = "information" ,
102
- message = 'Type of "attrs.AttrsInstance" is "Any "' ,
103
+ message = 'Type of "attrs.AttrsInstance" is "Type[AttrsInstance] "' ,
103
104
),
104
105
}
105
106
assert diagnostics == expected_diagnostics
You can’t perform that action at this time.
0 commit comments