Skip to content

Commit fbb5a84

Browse files
ncoghlansobolevn
andauthored
Add __struct_encode_fields__ to type stub (#813)
Static type checkers currently complain if querying the encoded field names instead of the attribute names. --------- Co-authored-by: sobolevn <[email protected]>
1 parent 7f9e55c commit fbb5a84

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

‎tests/typing/basic_typing_examples.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,7 @@ class Point(msgspec.Struct):
343343
x: int
344344
y: int
345345

346-
for field in Point.__struct_fields__:
347-
assert_type(field, str)
346+
assert_type(Point.__struct_fields__, tuple[str, ...])
348347

349348
for field in Point.__match_args__:
350349
# mypy inferences `field` as `str`,
@@ -353,8 +352,8 @@ class Point(msgspec.Struct):
353352

354353
p = Point(1, 2)
355354

356-
for field in p.__struct_fields__:
357-
assert_type(field, str)
355+
assert_type(p.__struct_fields__, tuple[str, ...])
356+
assert_type(p.__struct_encode_fields__, tuple[str, ...])
358357

359358

360359
def check_struct_config() -> None:

0 commit comments

Comments
 (0)