Adding check to be used only for plugins

This commit is contained in:
Vishal 2024-07-25 23:48:44 +05:30 committed by GitHub
parent a1007b10fb
commit 6002525af1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -67,7 +67,10 @@ def existing(obj: ExistableT | None) -> ExistableT | None:
return obj if obj is not None and obj.exists() else None
def getclass(name: str, subclassof: type[T]) -> type[T]:
def getclass(name: str,
subclassof: type[T],
check_sdlib_modulename_clash: bool = False
) -> type[T]:
"""Given a full class name such as foo.bar.MyClass, return the class.
Category: **General Utility Functions**
@ -80,7 +83,7 @@ def getclass(name: str, subclassof: type[T]) -> type[T]:
splits = name.split('.')
modulename = '.'.join(splits[:-1])
classname = splits[-1]
if modulename in sys.stdlib_module_names:
if modulename in sys.stdlib_module_names and check_sdlib_modulename_clash:
raise Exception(f'{modulename} is an inbuilt module.')
module = importlib.import_module(modulename)
cls: type = getattr(module, classname)