-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from Chaste/13-update-template-syntax
Update template syntax
- Loading branch information
Showing
5 changed files
with
21 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
import inspect | ||
from collections.abc import Iterable | ||
|
||
|
||
class ClassDict: | ||
class TemplateClassDict: | ||
|
||
def __init__(self, template_dict): | ||
self._dict = {} | ||
for arg_tuple, clas in template_dict.items(): | ||
for arg_tuple, cls in template_dict.items(): | ||
if not inspect.isclass(cls): | ||
raise TypeError("Expected class, got {}".format(type(cls))) | ||
if not isinstance(arg_tuple, Iterable): | ||
arg_tuple = (arg_tuple,) | ||
key = tuple(str(arg) for arg in arg_tuple) | ||
self._dict[key] = clas | ||
key = tuple( | ||
arg.__name__ if inspect.isclass(arg) else str(arg) for arg in arg_tuple | ||
) | ||
self._dict[key] = cls | ||
|
||
def __getitem__(self, arg_tuple): | ||
if not isinstance(arg_tuple, Iterable): | ||
arg_tuple = (arg_tuple,) | ||
key = tuple(str(arg) for arg in arg_tuple) | ||
key = tuple( | ||
arg.__name__ if inspect.isclass(arg) else str(arg) for arg in arg_tuple | ||
) | ||
return self._dict[key] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters