Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if isinstance(target, str):
target = resolve(target, package=self.target.__name__)
if isinstance(source, str):
source = resolve(source, package=self.source.__name__)
elif source is None:
# Deal with nested modules in a pack
# Test for corresponding module relative to current source
source_name = target.__name__.replace('.', self.module_sep)
with suppress(ImportError):
source = resolve(source_name, package=self.source.__name__)
if isinstance(target, ModuleType):
if source:
logger.info('Patching {} using {}'.format(target.__name__, source.__name__))
return PatchModule(target, source, self.module_sep)
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)