Coder Social home page Coder Social logo

Comments (14)

prologic avatar prologic commented on May 26, 2024

Where if any of is this used and relied upon internally?
On May 13, 2015 4:38 PM, "spaceone" [email protected] wrote:

BaseComponent/Manager implements bool/nonzero which returns True if
there are pending events.
As it is a API to inherit from BaseComponent this is error prone.
I needed a lot time to debug the lines:

if arg:
foo()

which failed but worked finally with if arg is not None: (where arg is a
component, e.g. event.value.manager).

We should not overwrite pythons expected default behavior in the API and
instead hide internals like those.


Reply to this email directly or view it on GitHub
#51.

from circuits.

spaceone avatar spaceone commented on May 26, 2024

At least in circuits/tests/core/test_core.py

from circuits.

prologic avatar prologic commented on May 26, 2024

Seems we removed this already

from circuits.

spaceone avatar spaceone commented on May 26, 2024

hmm? Nothing is done here, yet.
bool/nonzero is still implemented

And the mentioned test case also still contains:
27 while app:
28 app.flush()

from circuits.

prologic avatar prologic commented on May 26, 2024

Show me? I grepped the codebase and could not find anything that implements this!

from circuits.

spaceone avatar spaceone commented on May 26, 2024

circuits/circuits/core/manager.py

 230     def __len__(self):
 231         """x.__len__() <==> len(x)
 232 
 233         Returns the number of events in the Event Queue.
 234         """
 235 
 236         return len(self._queue)

from circuits.

prologic avatar prologic commented on May 26, 2024

Ahh yes but this doesn't implement __nonzero__. This gives you the queue length (no. of events in the queue) of a component (usually you want len(self.root))

from circuits.

prologic avatar prologic commented on May 26, 2024

You should still be able to implement your own __nonzero__ however in a component subclass.

from circuits.

spaceone avatar spaceone commented on May 26, 2024
>>> class Foo(object):                                                                                                                                                                                                                                                           
...     def __len__(self):                                                                                                                                                                                                                                                       
...         return 0                                                                                                                                                                                                                                                             
... 
>>> 
>>> 
>>> f = Foo()
>>> bool(f)
False

from circuits.

prologic avatar prologic commented on May 26, 2024

So I'm proposing the following new public API(s):

  • .empty
  • .qsize

both properties.

Okay with this?

from circuits.

spaceone avatar spaceone commented on May 26, 2024

uhm, no? I would leave __len__ as it is. But i would implement __bool__ and __nonzero__ to return True.

from circuits.

prologic avatar prologic commented on May 26, 2024

Oh man! Is that what you meant all along? sigh We need to improve are communications! I was totally lost as to what you were proposing :)

Let's try this again!

git checkout -- .
``

LOL

from circuits.

prologic avatar prologic commented on May 26, 2024

All this work I did for nothing and all the tests passing too :) Haha :)

from circuits.

spaceone avatar spaceone commented on May 26, 2024

I'm really sorry :D You can use sed now to replace it: s/app.empty/len(app)/g.
Using properties here would be a disadvantage as they slow down the whole thing.

from circuits.

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.