Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving class loading efficiency and considering dynamic type list #919

Merged
merged 17 commits into from
Apr 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Option 2 for considering dynamic type list as mentioned in #765: crea…
…ted an non-cached version of get_class (get_class_nc) and used in get_class to avoid dynamic list issue as mentioned in comments of #765 as pointed out my Hector.
J007X committed Feb 1, 2023
commit 30d1e236d9d2f2f90fa24c228dd144b18b2d5257
4 changes: 2 additions & 2 deletions forte/data/data_store.py
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
from sortedcontainers import SortedList
from typing_inspect import get_origin, get_args, is_generic_type

from forte.utils import get_class
from forte.utils import get_class, get_class_nc
from forte.utils.utils import get_full_module_name
from forte.data.ontology.code_generation_objects import EntryTree
from forte.data.ontology.ontology_code_generator import OntologyCodeGenerator
@@ -879,7 +879,7 @@ def _is_subclass(
if cls_qualified_name in type_name_parent_class:
return True
else:
entry_class = get_class(type_name)
entry_class = get_class_nc(type_name)
if issubclass(entry_class, cls):
type_name_parent_class.add(cls_qualified_name)
return True
7 changes: 7 additions & 0 deletions forte/utils/utils.py
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
"get_full_module_name",
"get_class_name",
"get_class",
"get_class_nc",
"get_qual_name",
"create_class_with_kwargs",
"check_type",
@@ -81,6 +82,12 @@ def get_class_name(o, lower: bool = False) -> str:

@lru_cache
def get_class(class_name: str, module_paths: Optional[List[str]] = None):
r"""This is the cached version of get_class_nc.
"""
return get_class_nc(str, module_paths)


def get_class_nc(class_name: str, module_paths: Optional[List[str]] = None):
r"""Returns the class based on class name.

Args: