-
-
Notifications
You must be signed in to change notification settings - Fork 654
Description
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.)
Depends on #32899
Component: refactoring
Author: Matthias Koeppe
Branch: 7adef96
Reviewer: Jonathan Kliem
Issue created by migration from https://trac.sagemath.org/ticket/33017