Skip to content

Commit

Permalink
Better dummies (huggingface#15148)
Browse files Browse the repository at this point in the history
* Better dummies

* See if this fixes the issue

* Fix quality

* Style

* Add doc for DummyObject
  • Loading branch information
sgugger authored Jan 14, 2022
1 parent b212ff9 commit 1b730c3
Show file tree
Hide file tree
Showing 15 changed files with 2,345 additions and 5,934 deletions.
12 changes: 12 additions & 0 deletions src/transformers/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,18 @@ def requires_backends(obj, backends):
raise ImportError("".join([BACKENDS_MAPPING[backend][1].format(name) for backend in backends]))


class DummyObject(type):
"""
Metaclass for the dummy objects. Any class inheriting from it will return the ImportError generated by
`requires_backend` each time a user tries to access any method of that class.
"""

def __getattr__(cls, key):
if key.startswith("_"):
return super().__getattr__(cls, key)
requires_backends(cls, cls._backends)


def add_start_docstrings(*docstr):
def docstring_decorator(fn):
fn.__doc__ = "".join(docstr) + (fn.__doc__ if fn.__doc__ is not None else "")
Expand Down
Loading

0 comments on commit 1b730c3

Please sign in to comment.