mirror of https://github.com/Mikaela/Limnoria.git
*Really* optimized objects command.
This commit is contained in:
parent
02ce886b55
commit
abd94e32fb
|
@ -480,15 +480,26 @@ class FunCommands(callbacks.Privmsg):
|
||||||
"""takes no arguments.
|
"""takes no arguments.
|
||||||
|
|
||||||
Returns the number and types of Python objects in memory."""
|
Returns the number and types of Python objects in memory."""
|
||||||
def istype(t):
|
classes = 0
|
||||||
return lambda x: isinstance(x, t)
|
functions = 0
|
||||||
|
modules = 0
|
||||||
|
dicts = 0
|
||||||
|
lists = 0
|
||||||
|
tuples = 0
|
||||||
objs = gc.get_objects()
|
objs = gc.get_objects()
|
||||||
classes = ilen(itertools.ifilter(inspect.isclass, objs))
|
for obj in objs:
|
||||||
functions = ilen(itertools.ifilter(inspect.isroutine, objs))
|
if isinstance(obj, tuple):
|
||||||
modules = ilen(itertools.ifilter(inspect.ismodule, objs))
|
tuples += 1
|
||||||
dicts = ilen(itertools.ifilter(istype(dict), objs))
|
elif inspect.isroutine(obj):
|
||||||
lists = ilen(itertools.ifilter(istype(list), objs))
|
functions += 1
|
||||||
tuples = ilen(itertools.ifilter(istype(tuple), objs))
|
elif isinstance(obj, dict):
|
||||||
|
dicts += 1
|
||||||
|
elif isinstance(obj, list):
|
||||||
|
lists += 1
|
||||||
|
elif inspect.isclass(obj):
|
||||||
|
classes += 1
|
||||||
|
elif inspect.ismodule(obj):
|
||||||
|
modules += 1
|
||||||
response = 'I have %s objects: %s modules, %s classes, %s functions, '\
|
response = 'I have %s objects: %s modules, %s classes, %s functions, '\
|
||||||
'%s dictionaries, %s lists, and %s tuples (and a few other'\
|
'%s dictionaries, %s lists, and %s tuples (and a few other'\
|
||||||
' different types).' %\
|
' different types).' %\
|
||||||
|
|
Loading…
Reference in New Issue