File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ This library adheres to
16
16
(`#432 <https://github.com/agronholm/typeguard/issues/432 >`_, PR by Yongxin Wang)
17
17
- Fixed detection of optional fields (``NotRequired[...] ``) in ``TypedDict `` when using
18
18
forward references (`#424 <https://github.com/agronholm/typeguard/issues/424 >`_)
19
+ - Fixed mapping checks against Django's ``MultiValueDict ``
20
+ (`#419 <https://github.com/agronholm/typeguard/issues/419 >`_)
19
21
20
22
**4.1.5 ** (2023-09-11)
21
23
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
- from collections .abc import Collection
3
+ from collections .abc import Iterable
4
4
from dataclasses import dataclass
5
5
from enum import Enum , auto
6
6
from typing import TYPE_CHECKING , TypeVar
@@ -49,11 +49,11 @@ class CollectionCheckStrategy(Enum):
49
49
FIRST_ITEM = auto ()
50
50
ALL_ITEMS = auto ()
51
51
52
- def iterate_samples (self , collection : Collection [T ]) -> Collection [T ]:
52
+ def iterate_samples (self , collection : Iterable [T ]) -> Iterable [T ]:
53
53
if self is CollectionCheckStrategy .FIRST_ITEM :
54
- if len ( collection ) :
54
+ try :
55
55
return [next (iter (collection ))]
56
- else :
56
+ except StopIteration :
57
57
return ()
58
58
else :
59
59
return collection
Original file line number Diff line number Diff line change @@ -433,6 +433,14 @@ def test_bad_value_type_full_check(self):
433
433
collection_check_strategy = CollectionCheckStrategy .ALL_ITEMS ,
434
434
).match ("value of key 'y' of dict is not an instance of int" )
435
435
436
+ def test_custom_dict_generator_items (self ):
437
+ class CustomDict (dict ):
438
+ def items (self ):
439
+ for key in self :
440
+ yield key , self [key ]
441
+
442
+ check_type (CustomDict (a = 1 ), Dict [str , int ])
443
+
436
444
437
445
class TestTypedDict :
438
446
@pytest .mark .parametrize (
You can’t perform that action at this time.
0 commit comments