-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] feat: ForFilter generator helper for builtins.filter
#19643
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
base: master
Are you sure you want to change the base?
Changes from all commits
b3f3eab
67818c6
74b7a6e
eeb09ab
ddc13b8
fc12cea
5ce8148
54ad04e
eae9209
9941d54
71b27ef
5237f0b
d68b833
c9680dc
5bf4b22
c39bb4a
8e43b2e
9dceb9a
7c8053f
8aff832
0d2c019
cec1a5d
5170a10
ba5a978
572793c
55ed2d6
dbbbb57
0bc1d26
7d56fa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,5 @@ These variants of statements have custom implementations: | |
* ``for ... in seq:`` (for loop over a sequence) | ||
* ``for ... in enumerate(...):`` | ||
* ``for ... in zip(...):`` | ||
* ``for ... in filter(...):`` | ||
* ``for ... in itertools.filterfalse(...):`` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in my comment, this seems rare enough that it doesn't seem worth it to support it. Every special case adds some overhead to users, as they may try to remember all the stdlib features with optimized primitives. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there currently any API for a "mypyc plugin" like a mypy plugin? Or future plans for one? Could be cool to have a mypyc functools plugin and a mypyc itertools plugin, etc, to cover special casing of things that don't necessarily belong in the main mypy repo something like iterools.accumulate would see quite large performance increases if we could handle the math operations in C. (this is something I wanted/needed for my own libs and was driving towards with these generator helpers but I'll just fork mypy for now to implement) but to compile optimized C code for other fun things like functools.lru_cache and functools.cached_property would be really really cool (and fast) (and useful (in niche cases)) if there was a way it could be done without polluting the main repo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. though I do think some functools special casing might still be appropriate in the main repo, if not now as a longer term goal. even though that isn't the current way things are done, it seems like we've already started in that direction (see the singledispatch feature set) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we just implement but don't document this, so as to add no overhead to users? |
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.
Have you considered supporting
list(filter(...))
as well -- this seems quite common (in a follow-up PR)?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.
Yep, I actually have that drafted already. but it won't be a special case for
list(filter(...))
it will be a special case for[list|tuple|set](some_builtin_we_have_a_helper_for_in_for_helpers(...))
which will account for any builtin we have ForGenerator helpers forUh oh!
There was an error while loading. Please reload this page.
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.
Fwiw this was part of the intent behind the list-built-from-range tests
I wasn't actually testing that we can build a list from a range, I was preparing IR to reflect how this helper would change the C implementation. Will work for map, filter, range, zip, enumerate, and future ops with special-case gen helpers