Giter VIP home page Giter VIP logo

Comments (2)

Digenis avatar Digenis commented on May 21, 2024

2012-06-07: Different in custom list casting
(the commit in the last reply (5c7fa43f9bb6) was reverted 6 months later by da784fe683c0)

2012-10-06: PEP0424

2014-06-25: __len__ magic method is invoked when using list comprehensions

As long as __len__ exists, I guess the implementation can call it whenever it chooses.

When this happens with big sequences,
long breaks for computations may occur "randomly"
(actually whenever the implementation chooses to call __len__)
which the iterators optimization a slowdown in some cases.

The rewrite branch also has this problem.
There the optimization will just not work (when the interpreter arbitrarily calls __len__)
but at least not causing a slowdown.

My suggestion is not implementing __len__ at all
and name another method in place of it.
It would help if __len__ wasn't called under the hood here and there
but it seems this is not the case.

Perhaps you can have an attribute set to the length of a sequence when known
and experiment raising some exception when not,
imitating a smarter __length_hint__.
All this keeping aside this other length method
which will have a notice that it may get as computationally expensive as realizing the iterator.

from pyfunctional.

EntilZha avatar EntilZha commented on May 21, 2024

In the end went with the solution of removing __len__, while keeping the len and size methods. Removed here: bd391ae

That should resolve this issue.

from pyfunctional.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.