Last active
December 18, 2015 02:29
-
-
Save dreid/5711333 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
from twisted.python._reflectpy3 import namedAny | |
from twisted.python.deprecate import _fullyQualifiedName | |
import inspect | |
import types | |
tests = [] | |
for k, v in inspect.__dict__.items(): | |
if k.startswith('is'): | |
tests.append(('inspect.%s' % (k,), v)) | |
tests.extend([ | |
('types.FunctionType', lambda x: isinstance(x, types.FunctionType)), | |
('types.MethodType', lambda x: isinstance(x, types.MethodType)), | |
('types.BuiltinMethodType', lambda x: isinstance(x, types.BuiltinMethodType)), | |
('reflect.fullyQualifiedName', _fullyQualifiedName), | |
('obj.__name__', lambda x: x.__name__), | |
('reflect.namedAny', lambda x: namedAny(_fullyQualifiedName(x))) | |
]) | |
for n, t in tests: | |
print("%s:\t%r" % (n.ljust(30), t(int.__add__))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(twisted-pypy)thomasina dreid:twisted (fullyQualifiedName-methoddescriptor-5644-3)> python builtin_fqn.py | |
inspect.isgenerator : False | |
inspect.isdatadescriptor : False | |
inspect.isframe : False | |
inspect.ismemberdescriptor : False | |
inspect.isabstract : False | |
inspect.isbuiltin : False | |
inspect.isfunction : False | |
inspect.istraceback : False | |
inspect.isgeneratorfunction : False | |
inspect.ismethod : True | |
inspect.iscode : False | |
inspect.isclass : False | |
inspect.ismethoddescriptor : False | |
inspect.isroutine : True | |
inspect.ismodule : False | |
inspect.isgetsetdescriptor : False | |
types.FunctionType : False | |
types.MethodType : True | |
types.BuiltinMethodType : True | |
reflect.fullyQualifiedName : '__builtin__.int.__add__' | |
obj.__name__ : '__add__' | |
reflect.namedAny : <unbound method int.__add__> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(twisted)thomasina dreid:twisted (fullyQualifiedName-methoddescriptor-5644-3)> python builtin_fqn.py | |
inspect.isgenerator : False | |
inspect.isdatadescriptor : False | |
inspect.isframe : False | |
inspect.ismemberdescriptor : False | |
inspect.isabstract : False | |
inspect.isbuiltin : False | |
inspect.isfunction : False | |
inspect.istraceback : False | |
inspect.isgeneratorfunction : False | |
inspect.ismethod : False | |
inspect.iscode : False | |
inspect.isclass : False | |
inspect.ismethoddescriptor : True | |
inspect.isroutine : True | |
inspect.ismodule : False | |
inspect.isgetsetdescriptor : False | |
types.FunctionType : False | |
types.MethodType : False | |
types.BuiltinMethodType : False | |
reflect.fullyQualifiedName : '__add__' | |
obj.__name__ : '__add__' | |
Traceback (most recent call last): | |
File "builtin_fqn.py", line 25, in <module> | |
print("%s:\t%r" % (n.ljust(30), t(int.__add__))) | |
File "builtin_fqn.py", line 21, in <lambda> | |
('reflect.namedAny', lambda x: namedAny(_fullyQualifiedName(x))) | |
File "/Users/dreid/code/twisted/twisted/python/_reflectpy3.py", line 271, in namedAny | |
raise ModuleNotFound("No module named %r" % (name,)) | |
twisted.python._reflectpy3.ModuleNotFound: No module named '__add__' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(twisted-py3)thomasina dreid:twisted (fullyQualifiedName-methoddescriptor-5644-3)> python builtin_fqn.py | |
inspect.isdatadescriptor : False | |
inspect.ismethoddescriptor : True | |
inspect.ismodule : False | |
inspect.ismemberdescriptor : False | |
inspect.isgetsetdescriptor : False | |
inspect.iscode : False | |
inspect.istraceback : False | |
inspect.isbuiltin : False | |
inspect.ismethod : False | |
inspect.isclass : False | |
inspect.isgeneratorfunction : False | |
inspect.isgenerator : False | |
inspect.isabstract : False | |
inspect.isfunction : False | |
inspect.isroutine : True | |
inspect.isframe : False | |
types.FunctionType : False | |
types.MethodType : False | |
types.BuiltinMethodType : False | |
reflect.fullyQualifiedName : 'int.__add__' | |
obj.__name__ : '__add__' | |
Traceback (most recent call last): | |
File "builtin_fqn.py", line 25, in <module> | |
print("%s:\t%r" % (n.ljust(30), t(int.__add__))) | |
File "builtin_fqn.py", line 21, in <lambda> | |
('reflect.namedAny', lambda x: namedAny(_fullyQualifiedName(x))) | |
File "/Users/dreid/code/twisted/twisted/python/_reflectpy3.py", line 273, in namedAny | |
raise ObjectNotFound('%r does not name an object' % (name,)) | |
twisted.python._reflectpy3.ObjectNotFound: 'int.__add__' does not name an object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment