Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e968bc73
Commit
e968bc73
authored
Oct 24, 2017
by
Thomas Kluyver
Committed by
Yury Selivanov
Oct 24, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-30639: Lazily compute repr for error (#2132)
parent
8e482bea
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
2 deletions
+13
-2
Lib/inspect.py
Lib/inspect.py
+3
-2
Lib/test/test_inspect.py
Lib/test/test_inspect.py
+8
-0
Misc/NEWS.d/next/Library/2017-10-24-12-24-56.bpo-30639.ptNM9a.rst
...S.d/next/Library/2017-10-24-12-24-56.bpo-30639.ptNM9a.rst
+2
-0
No files found.
Lib/inspect.py
View file @
e968bc73
...
...
@@ -662,8 +662,9 @@ def getfile(object):
object
=
object
.
f_code
if
iscode
(
object
):
return
object
.
co_filename
raise
TypeError
(
'{!r} is not a module, class, method, '
'function, traceback, frame, or code object'
.
format
(
object
))
raise
TypeError
(
'module, class, method, function, traceback, frame, or '
'code object was expected, got {}'
.
format
(
type
(
object
).
__name__
))
def
getmodulename
(
path
):
"""Return the module name for a given file, or None."""
...
...
Lib/test/test_inspect.py
View file @
e968bc73
...
...
@@ -463,6 +463,14 @@ class TestRetrievingSourceCode(GetSourceBase):
with
self
.
assertRaises
(
TypeError
):
inspect
.
getfile
(
C
)
def
test_getfile_broken_repr
(
self
):
class
ErrorRepr
:
def
__repr__
(
self
):
raise
Exception
(
'xyz'
)
er
=
ErrorRepr
()
with
self
.
assertRaises
(
TypeError
):
inspect
.
getfile
(
er
)
def
test_getmodule_recursion
(
self
):
from
types
import
ModuleType
name
=
'__inspect_dummy'
...
...
Misc/NEWS.d/next/Library/2017-10-24-12-24-56.bpo-30639.ptNM9a.rst
0 → 100644
View file @
e968bc73
:func:`inspect.getfile` no longer computes the repr of unknown objects to
display in an error message, to protect against badly behaved custom reprs.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment