@@ -360,7 +360,8 @@ class A:
360
360
361
361
a = A(5)
362
362
a.a = 16 # E: Property "a" defined in "A" is read-only
363
- [builtins fixtures/bool.pyi]
363
+ [builtins fixtures/plugin_attrs.pyi]
364
+
364
365
[case testAttrsNextGenFrozen]
365
366
from attr import frozen, field
366
367
@@ -370,7 +371,7 @@ class A:
370
371
371
372
a = A(5)
372
373
a.a = 16 # E: Property "a" defined in "A" is read-only
373
- [builtins fixtures/bool .pyi]
374
+ [builtins fixtures/plugin_attrs .pyi]
374
375
375
376
[case testAttrsNextGenDetect]
376
377
from attr import define, field
@@ -420,7 +421,7 @@ reveal_type(A) # N: Revealed type is "def (a: builtins.int, b: builtins.bool) -
420
421
reveal_type(B) # N: Revealed type is "def (a: builtins.bool, b: builtins.int) -> __main__.B"
421
422
reveal_type(C) # N: Revealed type is "def (a: builtins.int) -> __main__.C"
422
423
423
- [builtins fixtures/bool .pyi]
424
+ [builtins fixtures/plugin_attrs .pyi]
424
425
425
426
[case testAttrsDataClass]
426
427
import attr
@@ -1155,7 +1156,7 @@ c = NonFrozenFrozen(1, 2)
1155
1156
c.a = 17 # E: Property "a" defined in "NonFrozenFrozen" is read-only
1156
1157
c.b = 17 # E: Property "b" defined in "NonFrozenFrozen" is read-only
1157
1158
1158
- [builtins fixtures/bool .pyi]
1159
+ [builtins fixtures/plugin_attrs .pyi]
1159
1160
[case testAttrsCallableAttributes]
1160
1161
from typing import Callable
1161
1162
import attr
@@ -1178,7 +1179,7 @@ class G:
1178
1179
class FFrozen(F):
1179
1180
def bar(self) -> bool:
1180
1181
return self._cb(5, 6)
1181
- [builtins fixtures/callable .pyi]
1182
+ [builtins fixtures/plugin_attrs .pyi]
1182
1183
1183
1184
[case testAttrsWithFactory]
1184
1185
from typing import List
@@ -1450,7 +1451,7 @@ class C:
1450
1451
total = attr.ib(type=Bad) # E: Name "Bad" is not defined
1451
1452
1452
1453
C(0).total = 1 # E: Property "total" defined in "C" is read-only
1453
- [builtins fixtures/bool .pyi]
1454
+ [builtins fixtures/plugin_attrs .pyi]
1454
1455
1455
1456
[case testTypeInAttrDeferredStar]
1456
1457
import lib
@@ -1941,7 +1942,7 @@ class C:
1941
1942
default=None, converter=default_if_none(factory=dict) \
1942
1943
# E: Unsupported converter, only named functions, types and lambdas are currently supported
1943
1944
)
1944
- [builtins fixtures/dict .pyi]
1945
+ [builtins fixtures/plugin_attrs .pyi]
1945
1946
1946
1947
[case testAttrsUnannotatedConverter]
1947
1948
import attr
@@ -2012,7 +2013,7 @@ class Sub(Base):
2012
2013
2013
2014
@property
2014
2015
def name(self) -> str: ...
2015
- [builtins fixtures/property .pyi]
2016
+ [builtins fixtures/plugin_attrs .pyi]
2016
2017
2017
2018
[case testOverrideWithPropertyInFrozenClassChecked]
2018
2019
from attrs import frozen
@@ -2035,7 +2036,7 @@ class Sub(Base):
2035
2036
2036
2037
# This matches runtime semantics
2037
2038
reveal_type(Sub) # N: Revealed type is "def (*, name: builtins.str, first_name: builtins.str, last_name: builtins.str) -> __main__.Sub"
2038
- [builtins fixtures/property .pyi]
2039
+ [builtins fixtures/plugin_attrs .pyi]
2039
2040
2040
2041
[case testFinalInstanceAttribute]
2041
2042
from attrs import define
@@ -2380,3 +2381,82 @@ class B(A):
2380
2381
reveal_type(B.__hash__) # N: Revealed type is "None"
2381
2382
2382
2383
[builtins fixtures/plugin_attrs.pyi]
2384
+
2385
+ [case testManualOwnHashability]
2386
+ from attrs import define, frozen
2387
+
2388
+ @define
2389
+ class A:
2390
+ a: int
2391
+ def __hash__(self) -> int:
2392
+ ...
2393
+
2394
+ reveal_type(A.__hash__) # N: Revealed type is "def (self: __main__.A) -> builtins.int"
2395
+
2396
+ [builtins fixtures/plugin_attrs.pyi]
2397
+
2398
+ [case testSubclassDefaultLosesHashability]
2399
+ from attrs import define, frozen
2400
+
2401
+ @define
2402
+ class A:
2403
+ a: int
2404
+ def __hash__(self) -> int:
2405
+ ...
2406
+
2407
+ @define
2408
+ class B(A):
2409
+ pass
2410
+
2411
+ reveal_type(B.__hash__) # N: Revealed type is "None"
2412
+
2413
+ [builtins fixtures/plugin_attrs.pyi]
2414
+
2415
+ [case testSubclassEqFalseKeepsHashability]
2416
+ from attrs import define, frozen
2417
+
2418
+ @define
2419
+ class A:
2420
+ a: int
2421
+ def __hash__(self) -> int:
2422
+ ...
2423
+
2424
+ @define(eq=False)
2425
+ class B(A):
2426
+ pass
2427
+
2428
+ reveal_type(B.__hash__) # N: Revealed type is "def (self: __main__.A) -> builtins.int"
2429
+
2430
+ [builtins fixtures/plugin_attrs.pyi]
2431
+
2432
+ [case testSubclassingFrozenHashability]
2433
+ from attrs import define, frozen
2434
+
2435
+ @define
2436
+ class A:
2437
+ a: int
2438
+
2439
+ @frozen
2440
+ class B(A):
2441
+ pass
2442
+
2443
+ reveal_type(B.__hash__) # N: Revealed type is "def (self: builtins.object) -> builtins.int"
2444
+
2445
+ [builtins fixtures/plugin_attrs.pyi]
2446
+
2447
+ [case testSubclassingFrozenHashOffHashability]
2448
+ from attrs import define, frozen
2449
+
2450
+ @define
2451
+ class A:
2452
+ a: int
2453
+ def __hash__(self) -> int:
2454
+ ...
2455
+
2456
+ @frozen(unsafe_hash=False)
2457
+ class B(A):
2458
+ pass
2459
+
2460
+ reveal_type(B.__hash__) # N: Revealed type is "None"
2461
+
2462
+ [builtins fixtures/plugin_attrs.pyi]
0 commit comments