Skip to content

Commit 095c33c

Browse files
Ryan Nowakowskitubaman
authored andcommitted
Fix empty class generation
When generating a client for a schema that includes empty types, etc, add pass to the body.
1 parent e8458ec commit 095c33c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

ariadne_codegen/codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def generate_class_def(
117117
bases = cast(
118118
List[ast.expr], [ast.Name(id=name) for name in base_names] if base_names else []
119119
)
120-
body = body if body else []
120+
body = body if body else [ast.Pass()]
121121
if description:
122122
docstring = ast.Expr(value=ast.Constant(value=description))
123123
body.insert(0, docstring)

tests/codegen/test_generated_classes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ def test_generate_class_def_with_description_adds_docstring():
3838
assert isinstance(docstring, ast.Expr)
3939
assert isinstance(docstring.value, ast.Constant)
4040
assert docstring.value.value == description
41+
42+
43+
def test_generate_class_def_with_empty_body_adds_pass():
44+
name = "Xyz"
45+
46+
result = generate_class_def(name)
47+
48+
assert isinstance(result, ast.ClassDef)
49+
assert result.name == name
50+
pass_obj = result.body[0]
51+
assert isinstance(pass_obj, ast.Pass)

0 commit comments

Comments
 (0)