From 69d1b8fc0832f1cf00727c73eff6fbde11824c20 Mon Sep 17 00:00:00 2001 From: Matthew Donoughe Date: Fri, 21 Oct 2022 20:21:08 -0400 Subject: [PATCH] dirname cannot be falsey --- scrapy/commands/runspider.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scrapy/commands/runspider.py b/scrapy/commands/runspider.py index ed16c3fb6..22fa6a53d 100644 --- a/scrapy/commands/runspider.py +++ b/scrapy/commands/runspider.py @@ -15,13 +15,11 @@ def _import_file(filepath: Union[str, PathLike]) -> ModuleType: if abspath.suffix not in ('.py', '.pyw'): raise ValueError(f"Not a Python source file: {abspath}") dirname = str(abspath.parent) - if dirname: - sys.path = [dirname] + sys.path + sys.path = [dirname] + sys.path try: module = import_module(abspath.stem) finally: - if dirname: - sys.path.pop(0) + sys.path.pop(0) return module