MCPcopy
hub / github.com/msgspec/msgspec / __init_subclass__

Method __init_subclass__

tests/unit/test_struct.py:297–321  ·  view source on GitHub ↗
(cls)

Source from the content-addressed store, hash-verified

295
296 class Test(Struct):
297 def __init_subclass__(cls):
298 # Class attributes aren't yet defined, error nicely
299 for attr in [
300 "__struct_fields__",
301 "__struct_encode_fields__",
302 "__match_args__",
303 "__struct_defaults__",
304 ]:
305 with pytest.raises(AttributeError):
306 getattr(cls, attr)
307
308 # Init doesn't work
309 with pytest.raises(Exception):
310 cls()
311
312 # Decoder/decode doesn't work
313 for proto in [msgspec.json, msgspec.msgpack]:
314 with pytest.raises(ValueError, match="isn't fully defined"):
315 proto.Decoder(cls)
316
317 with pytest.raises(ValueError, match="isn't fully defined"):
318 proto.decode(b"", type=cls)
319
320 nonlocal ran
321 ran = True
322
323 class Subclass(Test):
324 x: int

Callers

nothing calls this directly

Calls 1

decodeMethod · 0.80

Tested by

no test coverage detected