File tree 2 files changed +6
-4
lines changed
2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -680,7 +680,8 @@ def collect_attributes(self) -> list[DataclassAttribute] | None:
680
680
)
681
681
682
682
current_attr_names .add (lhs .name )
683
- init_type = self ._infer_dataclass_attr_init_type (sym , lhs .name , stmt )
683
+ with state .strict_optional_set (self ._api .options .strict_optional ):
684
+ init_type = self ._infer_dataclass_attr_init_type (sym , lhs .name , stmt )
684
685
found_attrs [lhs .name ] = DataclassAttribute (
685
686
name = lhs .name ,
686
687
alias = alias ,
Original file line number Diff line number Diff line change @@ -1019,18 +1019,19 @@ class Desc:
1019
1019
def __get__(self, instance: object, owner: Any) -> str: ...
1020
1020
def __get__(self, instance, owner): ...
1021
1021
1022
- def __set__(self, instance: Any, value: bytes) -> None: ...
1022
+ def __set__(self, instance: Any, value: bytes | None ) -> None: ...
1023
1023
1024
1024
@my_dataclass
1025
1025
class C:
1026
1026
x: Desc
1027
1027
1028
1028
c = C(x=b'x')
1029
- C(x=1) # E: Argument "x" to "C" has incompatible type "int"; expected "bytes"
1029
+ c = C(x=None)
1030
+ C(x=1) # E: Argument "x" to "C" has incompatible type "int"; expected "Optional[bytes]"
1030
1031
reveal_type(c.x) # N: Revealed type is "builtins.str"
1031
1032
reveal_type(C.x) # N: Revealed type is "builtins.int"
1032
1033
c.x = b'x'
1033
- c.x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "bytes")
1034
+ c.x = 1 # E: Incompatible types in assignment (expression has type "int", variable has type "Optional[ bytes] ")
1034
1035
1035
1036
[typing fixtures/typing-full.pyi]
1036
1037
[builtins fixtures/dataclasses.pyi]
You can’t perform that action at this time.
0 commit comments