MCPcopy
hub / github.com/msgspec/msgspec / test_struct_instance_attributes

Function test_struct_instance_attributes

tests/unit/test_struct.py:114–131  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

112
113
114def test_struct_instance_attributes():
115 class Test(Struct):
116 c: int
117 b: float
118 a: str = "hello"
119
120 x = Test(1, 2.0, a="goodbye")
121
122 assert x.__struct_fields__ == ("c", "b", "a")
123 assert x.__struct_encode_fields__ == ("c", "b", "a")
124 assert x.__struct_fields__ is x.__struct_encode_fields__
125 assert x.__struct_defaults__ == ("hello",)
126 assert x.__slots__ == ("a", "b", "c")
127 assert isinstance(x.__struct_config__, StructConfig)
128
129 assert x.c == 1
130 assert x.b == 2.0
131 assert x.a == "goodbye"
132
133
134def test_struct_subclass_forbids_init_new_slots():

Callers

nothing calls this directly

Calls 1

TestClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…