mirror of
https://github.com/python/cpython.git
synced 2025-08-08 19:09:46 +00:00
[3.12] gh-123085: Fix issue in inferred caller when resources package has no source (GH-123102) (#124021)
gh-123085: Fix issue in inferred caller when resources package has no source.
From importlib_resources 6.4.3 (python/importlib_resourcesGH-314).
(cherry picked from commit a53812df12
)
This commit is contained in:
parent
09f7d88cad
commit
d712ece43f
3 changed files with 50 additions and 4 deletions
|
@ -93,12 +93,13 @@ def _infer_caller():
|
|||
"""
|
||||
|
||||
def is_this_file(frame_info):
|
||||
return frame_info.filename == __file__
|
||||
return frame_info.filename == stack[0].filename
|
||||
|
||||
def is_wrapper(frame_info):
|
||||
return frame_info.function == 'wrapper'
|
||||
|
||||
not_this_file = itertools.filterfalse(is_this_file, inspect.stack())
|
||||
stack = inspect.stack()
|
||||
not_this_file = itertools.filterfalse(is_this_file, stack)
|
||||
# also exclude 'wrapper' due to singledispatch in the call stack
|
||||
callers = itertools.filterfalse(is_wrapper, not_this_file)
|
||||
return next(callers).frame
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue