Skip to content

Commit 2eb3afe

Browse files
authored
Check if os.__file__ is available before using it (#1944)
* check if os.file is available before using it * use threading.__file__ als last fallback
1 parent b00a812 commit 2eb3afe

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_filtering.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ def _get_default_library_roots(cls):
155155

156156
# Make sure we always get at least the standard library location (based on the `os` and
157157
# `threading` modules -- it's a bit weird that it may be different on the ci, but it happens).
158-
roots.append(os.path.dirname(os.__file__))
158+
if hasattr(os, "__file__"):
159+
roots.append(os.path.dirname(os.__file__))
159160
roots.append(os.path.dirname(threading.__file__))
160161
if IS_PYPY:
161162
# On PyPy 3.6 (7.3.1) it wrongly says that sysconfig.get_path('stdlib') is

src/debugpy/_vendored/pydevd/pydevd_file_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,14 @@ def _get_library_dir():
8888
break
8989

9090
if library_dir is None or not os_path_exists(library_dir):
91-
library_dir = os.path.dirname(os.__file__)
91+
if hasattr(os, "__file__"):
92+
# "os" is a frozen import an thus "os.__file__" is not always set.
93+
# See https://github.com/python/cpython/pull/28656
94+
library_dir = os.path.dirname(os.__file__)
95+
else:
96+
# "threading" is not a frozen import an thus "threading.__file__" is always set.
97+
import threading
98+
library_dir = os.path.dirname(threading.__file__)
9299

93100
return library_dir
94101

0 commit comments

Comments
 (0)