From cdfcbd828ec37a1926d1a9b0231222cd47c20c85 Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Mon, 22 Mar 2021 15:29:11 +0100 Subject: [PATCH] depend: work around the potential None referer in get_co_using_ctypes If `ctypes` is (manually) added to hidden imports under python 3.7, one of `referers` entries processed in `get_co_using_ctypes()` method of `PyiModuleGraph` ends up being None. This in turn causes error when its `identifier` property is accessed, causing #3825. Work around the problem by explicitly skipping `None` entries. Fixes #3825. --- PyInstaller/depend/analysis.py | 5 +++++ news/3825.bugfix.rst | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 news/3825.bugfix.rst diff --git a/PyInstaller/depend/analysis.py b/PyInstaller/depend/analysis.py index b4f87b31f5..c33dc446f3 100644 --- a/PyInstaller/depend/analysis.py +++ b/PyInstaller/depend/analysis.py @@ -741,6 +741,11 @@ def get_co_using_ctypes(self): if node: referers = self.getReferers(node) for r in referers: + # Under python 3.7 and earlier, if ctypes is added to + # hidden imports, one of referers ends up being None, + # causing #3825. Work around it. + if r is None: + continue r_ident = r.identifier # Ensure that modulegraph objects has attribute 'code'. if type(r).__name__ in pure_python_module_types: diff --git a/news/3825.bugfix.rst b/news/3825.bugfix.rst new file mode 100644 index 0000000000..94d84192cc --- /dev/null +++ b/news/3825.bugfix.rst @@ -0,0 +1,2 @@ +Fix the build-time error under python 3.7 and earlier when ``ctypes`` +is manually added to ``hiddenimports``.