Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def patchy(target, source=None):
""" If source is not supplied, auto updates cannot be applied """
if isinstance(target, str):
target = resolve(target)
if isinstance(source, str):
source = resolve(source)
if isinstance(target, ModuleType):
return PatchModule(target, source)
elif isinstance(target, type) and source:
return PatchClass(target, source)
def cls(self, target, source=None):
if isinstance(target, str):
target = resolve(target, package=self.target)
if self.source and source is None:
with suppress(ImportError):
source_str = '{mod}.{cls}'.format(
mod=target.__module__.replace('.', self.module_sep),
cls=target.__name__)
source = resolve(source_str, package=self.source)
if not source:
with suppress(AttributeError):
source = getattr(self.source, target.__name__)
elif isinstance(source, str):
source = resolve(source, package=self.source)
if isinstance(target, type):
return PatchClass(target, source)
raise TypeError('Must be a valid class or class name')