Skip to content

Commit

Permalink
Only generate __init__ for classes that have constructor signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
unexge committed Jan 3, 2023
1 parent 5e56f45 commit fb5bcd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class PythonApplicationGenerator(
"""
##[#{pyo3}::pyclass]
##[derive(Debug)]
/// :rtype None:
pub struct App {
handlers: #{HashMap}<String, #{SmithyPython}::PyHandler>,
middlewares: Vec<#{SmithyPython}::PyMiddlewareHandler>,
Expand Down
12 changes: 10 additions & 2 deletions rust-runtime/aws-smithy-http-server-python/examples/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,16 @@ def make_class(
print(f"Unknown member type={member}")

if inspect.getdoc(klass) is not None:
is_empty = False
definition += make_function(writer, "__init__", klass, indent_level + 4) + "\n"
constructor_sig = DocstringParser.parse(klass)
if constructor_sig is not None and (
# Make sure to only generate `__init__` if the class has a constructor defined
len(constructor_sig.rtypes) > 0
or len(constructor_sig.params) > 0
):
is_empty = False
definition += (
make_function(writer, "__init__", klass, indent_level + 4) + "\n"
)

if is_empty:
definition += indent(f"...\n", indent_level + 4)
Expand Down

0 comments on commit fb5bcd7

Please sign in to comment.