Skip to content
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

Propagate length hint through generator expressions #147

Open
robertwb opened this issue Jul 29, 2016 · 2 comments
Open

Propagate length hint through generator expressions #147

robertwb opened this issue Jul 29, 2016 · 2 comments

Comments

@robertwb
Copy link
Owner

Reported by scoder on 19 Nov 2011 15:11 UTC
Python generators have a feature that presents a length hint to interested parties that can take advantage of it, such as "list()". Cython generator expressions should propagate the length hint of the underlying iterator if there is only one "for" loop and no "if" selector predicate. The C-API function to ask for a length hint is _PyObject_LengthHint(), which is available from Py2.5 on. Generator expressions would then need to provide a .__length_hint__() special method that returns either a constant result (when known at compile time, e.g. for sliced C arrays), or calls _PyObject_LengthHint() on the underlying iterator.

Migrated-From: http://trac.cython.org/ticket/756

@robertwb
Copy link
Owner Author

Modified by scoder on 23 Aug 2013 17:54 UTC

@robertwb
Copy link
Owner Author

Modified by scoder on 23 Aug 2013 17:54 UTC
Set description to

Python generators have a feature that presents a length hint to interested parties that can take advantage of it, such as "list()". Cython generator expressions should propagate the length hint of the underlying iterator if there is only one "for" loop and no "if" selector predicate. The C-API function to ask for a length hint is _PyObject_LengthHint(), which is available from Py2.5 on. Generator expressions would then need to provide a .__length_hint__() special method that returns either a constant result (when known at compile time, e.g. for sliced C arrays), or calls _PyObject_LengthHint() on the underlying iterator.

This should be easy to do once ticket http://trac.cython.org/ticket/600 is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant