mirror of https://github.com/python/cpython
Use AttributeError
This commit is contained in:
parent
2234bc9101
commit
946749f6fe
|
@ -11,27 +11,27 @@ def getattr(x, name):
|
||||||
def listattrs(x):
|
def listattrs(x):
|
||||||
try:
|
try:
|
||||||
dictkeys = x.__dict__.keys()
|
dictkeys = x.__dict__.keys()
|
||||||
except (NameError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
dictkeys = []
|
dictkeys = []
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
methods = x.__methods__
|
methods = x.__methods__
|
||||||
except (NameError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
methods = []
|
methods = []
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
members = x.__members__
|
members = x.__members__
|
||||||
except (NameError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
members = []
|
members = []
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
the_class = x.__class__
|
the_class = x.__class__
|
||||||
except (NameError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
the_class = None
|
the_class = None
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
bases = x.__bases__
|
bases = x.__bases__
|
||||||
except (NameError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
bases = ()
|
bases = ()
|
||||||
#
|
#
|
||||||
total = dictkeys + methods + members
|
total = dictkeys + methods + members
|
||||||
|
@ -69,7 +69,7 @@ def is_function(x):
|
||||||
# Use a class method to make a function that can be called
|
# Use a class method to make a function that can be called
|
||||||
# with or without arguments.
|
# with or without arguments.
|
||||||
#
|
#
|
||||||
class _dirclass():
|
class _dirclass:
|
||||||
def dir(args):
|
def dir(args):
|
||||||
if type(args) = type(()):
|
if type(args) = type(()):
|
||||||
return listattrs(args[1])
|
return listattrs(args[1])
|
||||||
|
|
|
@ -11,27 +11,27 @@ def getattr(x, name):
|
||||||
def listattrs(x):
|
def listattrs(x):
|
||||||
try:
|
try:
|
||||||
dictkeys = x.__dict__.keys()
|
dictkeys = x.__dict__.keys()
|
||||||
except (NameError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
dictkeys = []
|
dictkeys = []
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
methods = x.__methods__
|
methods = x.__methods__
|
||||||
except (NameError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
methods = []
|
methods = []
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
members = x.__members__
|
members = x.__members__
|
||||||
except (NameError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
members = []
|
members = []
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
the_class = x.__class__
|
the_class = x.__class__
|
||||||
except (NameError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
the_class = None
|
the_class = None
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
bases = x.__bases__
|
bases = x.__bases__
|
||||||
except (NameError, TypeError):
|
except (AttributeError, TypeError):
|
||||||
bases = ()
|
bases = ()
|
||||||
#
|
#
|
||||||
total = dictkeys + methods + members
|
total = dictkeys + methods + members
|
||||||
|
@ -69,7 +69,7 @@ def is_function(x):
|
||||||
# Use a class method to make a function that can be called
|
# Use a class method to make a function that can be called
|
||||||
# with or without arguments.
|
# with or without arguments.
|
||||||
#
|
#
|
||||||
class _dirclass():
|
class _dirclass:
|
||||||
def dir(args):
|
def dir(args):
|
||||||
if type(args) = type(()):
|
if type(args) = type(()):
|
||||||
return listattrs(args[1])
|
return listattrs(args[1])
|
||||||
|
|
Loading…
Reference in New Issue