From 591e5422eafa89b277a59ef1651552d7b6304698 Mon Sep 17 00:00:00 2001 From: Sergey Mishin Date: Thu, 14 Mar 2024 22:26:59 +0100 Subject: [PATCH] Handle modules with __file__ property being None It's been discovered that some modules have the `__file__` property being set as `None`. An example of a such module is `backports`. Providing `None` to `os.path.abspath()` causes an exception: `TypeError: expected str, bytes or os.PathLike object, not NoneType` Related to https://github.com/mitogen-hq/mitogen/issues/946 --- mitogen/master.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mitogen/master.py b/mitogen/master.py index b1e0a1de..db12229d 100644 --- a/mitogen/master.py +++ b/mitogen/master.py @@ -148,7 +148,11 @@ def is_stdlib_name(modname): return False # six installs crap with no __file__ - modpath = os.path.abspath(getattr(module, '__file__', '')) + path = getattr(module, '__file__', '') + if path is None: + path = '' + + modpath = os.path.abspath(path) return is_stdlib_path(modpath)