Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-26828: __length_hint__ method for map and zip#1077

Closed
MSeifert04 wants to merge 1 commit into
python:masterpython/cpython:masterfrom
MSeifert04:lengthhint_map_zipCopy head branch name to clipboard
Closed

bpo-26828: __length_hint__ method for map and zip#1077
MSeifert04 wants to merge 1 commit into
python:masterpython/cpython:masterfrom
MSeifert04:lengthhint_map_zipCopy head branch name to clipboard

Conversation

@MSeifert04

Copy link
Copy Markdown
Contributor

This is more or less just a test for bpo-26828.

I did some benchmarks and it seems the overhead for small iterables is significant (up to 20% slower for 10, 10 items long iterables) and the break-even seems to be at 50 (2 iterables) - 100 (10 iterables) items. However it takes 100k-1m elements in the benchmarks for the length_hint variant to be 20% faster.

However I'm not sure my micro-benchmarks are really accurate.

@mention-bot

Copy link
Copy Markdown

@MSeifert04, thanks for your PR! By analyzing the history of the files in this pull request, we identified @berkerpeksag, @ncoghlan and @serhiy-storchaka to be potential reviewers.

@brettcannon brettcannon added the type-feature A feature request or enhancement label Apr 17, 2017
@rhettinger rhettinger self-assigned this Apr 26, 2017
Comment thread Python/bltinmodule.c
}

if (length_hint == -1)
return NULL;

@nascheme nascheme Apr 28, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks incorrect to me. Shouldn't it test if it_len == PY_SSIZE_T_MAX? If this is a bug, your unit tests are not extensive enough. Add tests that feed generators to zip and map and check to ensure that __length_hint__ returns the correct value (None?) when no length can be determined.

@MSeifert04 MSeifert04 Apr 28, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it_len == PY_SSIZE_T_MAX should be valid because if there's no iterator then the function short-circuits immediatly but if there are iterators then PY_SSIZE_T_MAX is a valid length.

However the issue was recently challenged and eventually closed as "no fix" so I haven't continued here.

@MSeifert04 MSeifert04 closed this Apr 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.