schrodinger.utils.moduleproxy module

A module proxy class to be used when a non-essential module can’t be imported. It will raise an ImportError any time something from the module is accessed.

schrodinger.utils.moduleproxy.try_import(name)

Return the module named or a proxy that will raise an ImportError the first time any of its attributes are accessed.

This allows for a non-essential module to be imported and mostly ignored if not present.

class schrodinger.utils.moduleproxy.ModuleProxy(name)

Bases: object

A class to use as a placeholder for a non-essential module, raising an exception when something tries to use it.

__init__(name)

Initialize self. See help(type(self)) for accurate signature.

__getattr__(attr)

Simply raise an exception any time something tries to make use of functionality from the fake module.

__bool__()

Always return False, indicating that the instance is not usable as a module.

This allows for conditional behavior to be set up, based on a check for a proxy module. For example:

matplotlib = try_import(“matplotlib”)

if matplotlib:
create_pretty_graph()
else:
print_boring_numbers()
__class__

alias of builtins.type

__delattr__

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'schrodinger.utils.moduleproxy', '__doc__': '\n A class to use as a placeholder for a non-essential module, raising an\n exception when something tries to use it.\n\n ', '__init__': <function ModuleProxy.__init__>, '__getattr__': <function ModuleProxy.__getattr__>, '__bool__': <function ModuleProxy.__bool__>, '__dict__': <attribute '__dict__' of 'ModuleProxy' objects>, '__weakref__': <attribute '__weakref__' of 'ModuleProxy' objects>})
__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__

Return self<=value.

__lt__

Return self<value.

__module__ = 'schrodinger.utils.moduleproxy'
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)