Skip to content

Commit

Permalink
feat: raise TypeError if Corgy instantiated directly
Browse files Browse the repository at this point in the history
  • Loading branch information
jayanthkoushik committed Feb 1, 2022
1 parent c259117 commit a64b094
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions corgy/_corgy.py
Expand Up @@ -584,6 +584,9 @@ def add_args_to_parser(
parser.add_argument(*var_flags, type=var_add_type, **_kwargs)

def __init__(self, **args):
if self.__class__ is Corgy:
raise TypeError("`Corgy` is an abstract class and cannot be instantiated")

grp_args_map: Dict[str, Any] = defaultdict(dict)

for arg_name, arg_val in args.items():
Expand Down
4 changes: 4 additions & 0 deletions tests/test_corgy.py
Expand Up @@ -201,6 +201,10 @@ class D(Corgy):
d = D(x=1, c=c)
self.assertDictEqual(d.as_dict(), {"x": 1, "c": c})

def test_corgy_cls_raises_if_initialized_directly(self):
with self.assertRaises(TypeError):
Corgy()

def test_corgy_cls_usable_without_annotations(self):
class C(Corgy):
...
Expand Down

0 comments on commit a64b094

Please sign in to comment.