-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nondeterminism (including sometimes crashing) when using generics #109
Comments
Hey @patrick-kidger! Beartype's default strategy for checking whether a list is a Now, if at runtime you're using lists consisting only of one element type, this works fine. However, if your lists contain multiple types of elements, like in your example, you can run into problems. The simplest way to fix this is to use Reflecting on this, this should definitely be better documented somewhere. |
Yup, I'm actually familiar with the underlying reason! I wanted to highlight the silent downstream issue this is causing for plum. I don't think that documentation alone is enough. Until this is resolved in beartype, I'd suggest raising a warning or an error for this path instead. Is it possible to substitute out which runtime type checker is used in plum? I'm contemplating writing my own typechecker -- giving slow-but-correct O(n) checks on at least the types I care about -- and it'd be great to be able to use plum with it. |
Right! I figured you'd be familiar with what's going on. :) Substituting the runtime type checker should be possible. Plum fundamentally only depends on implementations of Do you have a suggestion for an interface? What about something like the following? dispatch = Dispatcher(type_checker=(isinstance, issubclass)) |
I think I like that API. I think you need at least one more piece though, which is Hypothetically we could imagine defining a custom |
Ah, that’s a super interesting proposal. Perhaps a class/dataclass If you manage a faithful implementation of type, then that would make isinstance redundant, so that would be convenient. Alright, I’m convinced! I’m not entirely sure when this will be finished, since it depends on how much spare time I have, but it shouldn’t be too long from now. :) |
rerunning this script will variably print out any one of the three branches, or sometimes crash with an
AmbiguousLookupError
.plum==2.2.2
;beartype==0.16.2
The text was updated successfully, but these errors were encountered: