-
-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trac #33017: LazyImport.__instancecheck__, __subclasscheck__: Return …
…False on ImportError No object is an instance of a class that cannot be imported. No class is a subclass of a class that cannot be imported. Hence, we change `LazyImport` so that the special methods `__instancecheck__`, `__subclasscheck__` catch `ImportError` and just return False. (We do not use the stronger versions of these two statements: "No object is an instance of a class that has not been imported yet (i.e., the module name is not in `sys.modules`)." These are true only if there are no re-exports.) With this change to `LazyImport`, we have another instrument for modularization of code that uses `isinstance` checks. (The use of `isinstance` with ABCs (#32566) is preferable because it avoids importing an otherwise unused implementation class.) URL: https://trac.sagemath.org/33017 Reported by: mkoeppe Ticket author(s): Matthias Koeppe Reviewer(s): Jonathan Kliem
- Loading branch information
Showing
2 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters