Open wakamex opened 4 months ago
here's an example of where the type narrowing is not correct
This type is incorrect, which means I can't auto-complete any of the random_hold_policy functions or discover the arguments.
and another for config:
these should be random hold policy & random hold policy config, which would have correct autocomplete.
I have a TODO in base.py:
# TODO: We add this as a helper property so that subclasses can access the config without
# overwriting the __init__ function. The downside is that users of this member variable
# can't be type checked. There's probably a way to do this with generics instead of Any.
This hints that the solution is to use Generics, which I still think is correct. We need to revamp IHyperdrive
to also use generics for this all to work.
The meta issue is that the python type system is fine with you narrowing the type to a base class, which removes all the metadata and content. So while it's not returning any type errors, it is not the behavior we want.
Move to medium priority bc the policy
attribute is intended to be private & not accessed by the user.
implement type narrowing all the way down to the lowest agent and policy level, through the use of generics right now policies are typed as only a very high-level
NoPolicy | BasePolicy
which isn't useful at all