diff --git a/xarray/core/utils.py b/xarray/core/utils.py index 3bbf06cf967..7111ebf2c0d 100644 --- a/xarray/core/utils.py +++ b/xarray/core/utils.py @@ -1248,7 +1248,12 @@ def find_stack_level(test_mode=False) -> int: pkg_dir = Path(xr.__file__).parent test_dir = pkg_dir / "tests" - std_lib_dir = Path(sys.modules["os"].__file__).parent # Standard library path + std_lib_path = sys.modules["os"].__file__ + # Mostly to appease mypy; I don't think this can happen... + if std_lib_path is None: + return 0 + + std_lib_dir = Path(std_lib_path).parent # Standard library path frame = inspect.currentframe() n = 0