Closed sscherfke closed 4 months ago
Solved it in Typed Settings, so fixing this is not super important. The __annotations__
dict being available for dynamic classes would be nice nonetheless, though.
Any reason you dumped a diff instead of a PR? 😅
It's just a draft for helping you decide whether you like this change or not. If you like it, I will prepare a PR. :-)
make_class()
currently doesn't touch the__annotations__
dict when it creates a new class.This can become a problem when a class is created dynamically with unresolved types. And when
__annotations__
is empty,resolve_type()
on the generated class will do nothing.Here is a use case: https://gitlab.com/sscherfke/typed-settings/-/issues/54
There's not much required to fix this:
The only problem with this is the unfortunate default of
field(type=None)
, b/c we cannot differentiate between an explicitNone
type an no type. I’m afraid though, that changing the default oftype=
to a sentinel object would be a braking change.