Skip to content

Commit

Permalink
Revert some performance optimizations
Browse files Browse the repository at this point in the history
- have been made in version 3.3.0,
  apparently cause hanging tests with torch import
- no performance degradation detected
- see #693
  • Loading branch information
mrbean-bremen committed Jul 23, 2022
1 parent 74e4e43 commit 4c64297
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# pyfakefs Release Notes
The released versions correspond to PyPi releases.

## Unreleased

### Fixes
* reverted a performance optimization introduced in version 3.3.0 that
caused hanging tests with installed torch (see [#693](../../issues/693))

## [Version 4.6.3](https://pypi.python.org/pypi/pyfakefs/4.6.3) (2022-07-20)
Another patch release that fixes a regression in version 4.6.

Expand Down
36 changes: 14 additions & 22 deletions pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,34 +605,26 @@ def _is_fs_module(self, mod: ModuleType,
name: str,
module_names: List[str]) -> bool:
try:
# check for __name__ first and ignore the AttributeException
# if it does not exist - avoids calling expansive ismodule
if mod.__name__ in module_names and inspect.ismodule(mod):
return True
return (inspect.ismodule(mod) and
mod.__name__ in module_names
or inspect.isclass(mod) and
mod.__module__ in self._class_modules.get(name, []))
except Exception:
pass
try:
if (name in self._class_modules and
mod.__module__ in self._class_modules[name]):
return inspect.isclass(mod)
except Exception:
# handle AttributeError and any other exception possibly triggered
# by side effects of inspect methods
pass
return False
# handle cases where the module has no __name__ or __module__
# attribute - see #460, and any other exception triggered
# by inspect functions
return False

def _is_fs_function(self, fct: FunctionType) -> bool:
try:
# check for __name__ first and ignore the AttributeException
# if it does not exist - avoids calling expansive inspect
# methods in most cases
return (fct.__name__ in self._fake_module_functions and
return ((inspect.isfunction(fct) or
inspect.isbuiltin(fct)) and
fct.__name__ in self._fake_module_functions and
fct.__module__ in self._fake_module_functions[
fct.__name__] and
(inspect.isfunction(fct) or inspect.isbuiltin(fct)))
fct.__name__])
except Exception:
# handle AttributeError and any other exception possibly triggered
# by side effects of inspect methods
# handle cases where the function has no __name__ or __module__
# attribute, or any other exception in inspect functions
return False

def _def_values(
Expand Down

0 comments on commit 4c64297

Please sign in to comment.