diff options
| author | Raphael Gaschignard <raphael@makeleaps.com> | 2019-11-26 14:41:48 +0900 |
|---|---|---|
| committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-11-26 08:41:39 +0100 |
| commit | 5cdefb0d278dfe80a662156a942472794df5ca67 (patch) | |
| tree | d8e6916844fdb608f5fba3a822f9a050886b2226 | |
| parent | 130406463f3c978571a7aca6e33c985e17848f21 (diff) | |
| download | astroid-git-5cdefb0d278dfe80a662156a942472794df5ca67.tar.gz | |
Avoid a call to `getcwd` if it is not needed
When profiling locally, approximately 7% of a full pylint run is spent in `os.getcwd`, despite its value effectively not being used if `context_file` is `None`. A quick grep over this project and others seem to indicate that `context_file` is rarely used, so this should almost entirely get rid of this system call.
| -rw-r--r-- | astroid/manager.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/astroid/manager.py b/astroid/manager.py index e5fd0d6b..4dad678a 100644 --- a/astroid/manager.py +++ b/astroid/manager.py @@ -128,8 +128,8 @@ class AstroidManager: return self.astroid_cache[modname] if modname == "__main__": return self._build_stub_module(modname) - old_cwd = os.getcwd() if context_file: + old_cwd = os.getcwd() os.chdir(os.path.dirname(context_file)) try: found_spec = self.file_from_module_name(modname, context_file) @@ -183,7 +183,8 @@ class AstroidManager: pass raise e finally: - os.chdir(old_cwd) + if context_file: + os.chdir(old_cwd) def zip_import_data(self, filepath): if zipimport is None: |
