-
Notifications
You must be signed in to change notification settings - Fork 74
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
WIP: Experiment to use pytypes to add support for python type hints #69
base: main
Are you sure you want to change the base?
Conversation
This is probably not going to work on py26 and pypy for now |
This seems cool to me. It would be good to check how this will affect performance. cc @llllllllll |
Do we have a more extensive suite we can benchmark for performance? |
Nope. There is a very small script in bench/ |
might be worth using something like pytest-benchmark if we want to be able to track performance over time |
I agree that that would be valuable. I am unlikely to set this up
personally, but would welcome such an addition.
…On Wed, Dec 27, 2017 at 11:29 AM, Marius van Niekerk < ***@***.***> wrote:
might be worth using something like pytest-benchmark if we want to be able
to track performance over time
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#69 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AASszBQyq9HRHzPX8a755O4NNZ0i_3nBks5tEpq2gaJpZM4RNvNY>
.
|
One area that might cause some issues is
|
To be clear, pytypes doesn't consider that a bug? |
Opened Stewori/pytypes#26 |
Failures are from
|
Most of the actual hard bits are delegated to pytypes for determining if types match expected instances.
f8cfd85
to
184df19
Compare
@llllllllll @mrocklin So i think this is ready for review again. Test failures on py37 due to some pytypes incompatibility |
if pytypes.is_Union(L[0]): | ||
rest = expand_tuples(L[1:]) | ||
return [(item,) + t for t in rest for item in pytypes.get_Union_params(L[0])] | ||
elif not pytypes.is_of_type(L[0], tuple): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
somehow this doesn't actually get hit when L[0]
is not a tuple:
(Pdb) p L[0]
<type 'numpy.dtype'>
(Pdb) p pytypes.is_of_type(L[0], tuple)
True
This breaks importing datashape
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The root cause of this is actually more concerning than this one bug. Why doesn't pytypes.is_of_type
work correctly for type objects?
I was trying to profile a real world application using this branch; however, the diff --git a/multipledispatch/utils.py b/multipledispatch/utils.py
index 816c7a4..8701756 100644
--- a/multipledispatch/utils.py
+++ b/multipledispatch/utils.py
@@ -32,6 +32,9 @@ def expand_tuples(L):
elif not pytypes.is_of_type(L[0], tuple):
rest = expand_tuples(L[1:])
return [(L[0],) + t for t in rest]
+ elif not isinstance(L[0], tuple):
+ rest = expand_tuples(L[1:])
+ return [(L[0],) + t for t in rest]
else:
rest = expand_tuples(L[1:])
return [(item,) + t for t in rest for item in L[0]] With this patch, I ran out of call stack space. I noticed that there is
This cycle occurs because we go through a |
So I haven't configured pytypes to do a subset for deep type. That might help. The recursion might still be a problem though. |
@llllllllll Can you point me to a test that i can run using this branch to see if i can correct the behavior? |
I don't have time to manually distil a minimal failure case; but the blaze test suite should be a very comprehensive use of multipledispatch. |
I've been working a bit on a branch a bit further along that adds in diagonal dispatch etc, but that requires pretty aggressive use of the typing system. Testing this with blaze (some constrained deps required to make blaze work).
This passes all but 1 of the tests, which might just be a dep mismatch somewhere. Looking at this again though, and after trying to dig through the blaze test suite, it might be better to have a different @dispatch function / Dispatcher that supports ONLY pep484 style type annotations and works only in py3. Alternatively we could add a parameter to dispatcher for pep484 mode vs original. blaze / odo could continue to use original annotations easily without any of the complex changes. cc @mrocklin. @llllllllll |
test failures are py37 (some weirdness) and py34 a strange flake |
Most of the actual hard bits are delegated to pytypes for determining if types match expected instances.