Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 946749f

Browse files
committed
Use AttributeError
1 parent 2234bc9 commit 946749f

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

Lib/lib-old/newdir.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ def getattr(x, name):
1111
def listattrs(x):
1212
try:
1313
dictkeys = x.__dict__.keys()
14-
except (NameError, TypeError):
14+
except (AttributeError, TypeError):
1515
dictkeys = []
1616
#
1717
try:
1818
methods = x.__methods__
19-
except (NameError, TypeError):
19+
except (AttributeError, TypeError):
2020
methods = []
2121
#
2222
try:
2323
members = x.__members__
24-
except (NameError, TypeError):
24+
except (AttributeError, TypeError):
2525
members = []
2626
#
2727
try:
2828
the_class = x.__class__
29-
except (NameError, TypeError):
29+
except (AttributeError, TypeError):
3030
the_class = None
3131
#
3232
try:
3333
bases = x.__bases__
34-
except (NameError, TypeError):
34+
except (AttributeError, TypeError):
3535
bases = ()
3636
#
3737
total = dictkeys + methods + members
@@ -69,7 +69,7 @@ def is_function(x):
6969
# Use a class method to make a function that can be called
7070
# with or without arguments.
7171
#
72-
class _dirclass():
72+
class _dirclass:
7373
def dir(args):
7474
if type(args) = type(()):
7575
return listattrs(args[1])

Lib/newdir.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ def getattr(x, name):
1111
def listattrs(x):
1212
try:
1313
dictkeys = x.__dict__.keys()
14-
except (NameError, TypeError):
14+
except (AttributeError, TypeError):
1515
dictkeys = []
1616
#
1717
try:
1818
methods = x.__methods__
19-
except (NameError, TypeError):
19+
except (AttributeError, TypeError):
2020
methods = []
2121
#
2222
try:
2323
members = x.__members__
24-
except (NameError, TypeError):
24+
except (AttributeError, TypeError):
2525
members = []
2626
#
2727
try:
2828
the_class = x.__class__
29-
except (NameError, TypeError):
29+
except (AttributeError, TypeError):
3030
the_class = None
3131
#
3232
try:
3333
bases = x.__bases__
34-
except (NameError, TypeError):
34+
except (AttributeError, TypeError):
3535
bases = ()
3636
#
3737
total = dictkeys + methods + members
@@ -69,7 +69,7 @@ def is_function(x):
6969
# Use a class method to make a function that can be called
7070
# with or without arguments.
7171
#
72-
class _dirclass():
72+
class _dirclass:
7373
def dir(args):
7474
if type(args) = type(()):
7575
return listattrs(args[1])

0 commit comments

Comments
 (0)