18
18
19
19
TYPE_CHECKING = False
20
20
if TYPE_CHECKING :
21
- from typing import Any , Protocol
21
+ from typing import Any , Callable , Protocol
22
22
23
23
class Spec (Protocol ):
24
24
prelude : str
@@ -27,8 +27,8 @@ class Spec(Protocol):
27
27
proto_prefix : str
28
28
29
29
30
- def with_indent (spaces : int , / ):
31
- def decorator (attr ) :
30
+ def with_indent (spaces : int , / ) -> Callable [[ str ], str ] :
31
+ def decorator (attr : str ) -> str :
32
32
return indent (dedent (attr ), " " * spaces )
33
33
34
34
return decorator
@@ -146,12 +146,13 @@ def create_protocol_source(
146
146
classes : dict [str , str ],
147
147
) -> str :
148
148
class_name = snake_to_pascal (class_name )
149
- docstring = f"""\
150
- { metadata .get ("description" , "" ).strip ()}
149
+ docstring = metadata .get ("description" , "" ).strip ()
150
+ if "@property" not in template .attr_def :
151
+ docstring += with_indent (4 )("""
151
152
152
- Attributes
153
- ----------
154
- """
153
+ Attributes
154
+ ----------
155
+ """)
155
156
156
157
required = metadata .get ("required" , {})
157
158
optional = [prop for prop in properties if prop not in required ]
@@ -172,7 +173,13 @@ def create_protocol_source(
172
173
name = prop_name , type = type_ , docstring = description , default = default
173
174
)
174
175
)
175
- docstring += f"{ prop_name } : { type_ } \n \t { description } \n "
176
+ # Avoid double-documenting properties
177
+ if "@property" not in template .attr_def :
178
+ docstring += with_indent (4 )(f"""\
179
+ { prop_name } : { type_ }
180
+ { description }
181
+
182
+ """ )
176
183
177
184
lines .insert (0 , template .class_def .format (name = class_name , docstring = docstring ))
178
185
0 commit comments