From cee33bbd7ebba0a3a9567210565813a29f95406a Mon Sep 17 00:00:00 2001 From: dev2718 Date: Thu, 13 Jan 2022 15:33:41 +0100 Subject: [PATCH] fix #4637 (#4639) Co-authored-by: Alexander Firbas --- news/fix-__file__-attribute.rst | 23 +++++++++++++++++++++++ xonsh/imphooks.py | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 news/fix-__file__-attribute.rst diff --git a/news/fix-__file__-attribute.rst b/news/fix-__file__-attribute.rst new file mode 100644 index 000000000..526d09a99 --- /dev/null +++ b/news/fix-__file__-attribute.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* If a .xsh file is imported, the resulting module will now always have an absolute \_\_file\_\_ attribute to be consistent with pythons behavior since python 3.4. + +**Security:** + +* diff --git a/xonsh/imphooks.py b/xonsh/imphooks.py index 41fc89491..9883168a8 100644 --- a/xonsh/imphooks.py +++ b/xonsh/imphooks.py @@ -75,7 +75,7 @@ class XonshImportHook(MetaPathFinder, SourceLoader): if fname not in {x.name for x in os.scandir(p)}: continue spec = ModuleSpec(fullname, self) - self._filenames[fullname] = os.path.join(p, fname) + self._filenames[fullname] = os.path.abspath(os.path.join(p, fname)) break return spec