fix bug in placer holder (#395)

* fix bug in placer holder

* remove redundent comment

Co-authored-by: liukai <your_email@abc.example>
pull/398/head
LKJacky 2022-12-13 10:56:13 +08:00 committed by GitHub
parent 1c03a07350
commit c8e14e5489
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 13 deletions

View File

@ -1,6 +1,4 @@
# Copyright (c) OpenMMLab. All rights reserved.
def get_placeholder(string: str) -> object:
"""Get placeholder instance which can avoid raising errors when down-stream
dependency is not installed properly.
@ -19,13 +17,7 @@ def get_placeholder(string: str) -> object:
raise ImportError(
f'`{package_name}` is not installed properly, plz check.')
class PlaceHolderMetaclass(type):
"""Used to support usage of PlaceHolder.xxxx."""
def __getattr__(self, name):
raise_import_error(string)
class PlaceHolder(metaclass=PlaceHolderMetaclass):
class PlaceHolder():
def __init__(self) -> None:
raise_import_error(string)

View File

@ -12,7 +12,7 @@ class TestPlaceholder(unittest.TestCase):
holder = get_placeholder('test')
with pytest.raises(ImportError):
holder()
with pytest.raises(ImportError):
holder.a
with pytest.raises(ImportError):
holder.a()
from mmrazor.models.architectures.dynamic_ops import DynamicMixin
class tmp(holder, DynamicMixin):
pass