Skip to content

Commit 9abaa5c

Browse files
committed
Swift: rename doc_name with doc in properties
1 parent 492d5ae commit 9abaa5c

File tree

9 files changed

+44
-44
lines changed

9 files changed

+44
-44
lines changed

swift/codegen/generators/qlgen.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,23 @@ def get_ql_property(cls: schema.Class, prop: schema.Property, prev_child: str =
7474
singular=inflection.camelize(prop.name),
7575
tablename=inflection.tableize(cls.name),
7676
tableparams=["this"] + ["result" if p is prop else "_" for p in cls.properties if p.is_single],
77-
doc_name=_humanize(prop.doc_name or prop.name),
77+
doc=_humanize(prop.doc or prop.name),
7878
)
7979
elif prop.is_repeated:
8080
args.update(
8181
singular=inflection.singularize(inflection.camelize(prop.name)),
8282
plural=inflection.pluralize(inflection.camelize(prop.name)),
8383
tablename=inflection.tableize(f"{cls.name}_{prop.name}"),
8484
tableparams=["this", "index", "result"],
85-
doc_name=_humanize(inflection.singularize(prop.doc_name or prop.name)),
86-
doc_name_plural=_humanize(inflection.pluralize(prop.doc_name or prop.name))
85+
doc=_humanize(inflection.singularize(prop.doc or prop.name)),
86+
doc_plural=_humanize(inflection.pluralize(prop.doc or prop.name))
8787
)
8888
elif prop.is_optional:
8989
args.update(
9090
singular=inflection.camelize(prop.name),
9191
tablename=inflection.tableize(f"{cls.name}_{prop.name}"),
9292
tableparams=["this", "result"],
93-
doc_name=_humanize(prop.doc_name or prop.name),
93+
doc=_humanize(prop.doc or prop.name),
9494
)
9595
elif prop.is_predicate:
9696
args.update(

swift/codegen/lib/ql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class Property:
3939
prev_child: Optional[str] = None
4040
qltest_skip: bool = False
4141
description: List[str] = field(default_factory=list)
42-
doc_name: Optional[str] = None
43-
doc_name_plural: Optional[str] = None
42+
doc: Optional[str] = None
43+
doc_plural: Optional[str] = None
4444

4545
def __post_init__(self):
4646
if self.tableparams:

swift/codegen/lib/schema/defs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def modify(self, prop: _schema.Property):
1313

1414
@_dataclass
1515
class _DocnameModifier(_schema.PropertyModifier):
16-
doc_name: str
16+
doc: str
1717

1818
def modify(self, prop: _schema.Property):
1919
if prop.is_predicate:
2020
raise _schema.Error("Predicates cannot have a doc name")
21-
prop.doc_name = self.doc_name
21+
prop.doc = self.doc
2222

2323

2424
@_dataclass
@@ -115,7 +115,7 @@ def f(cls: type) -> type:
115115
list = _TypeModifier(_Listifier())
116116

117117
child = _ChildModifier()
118-
docname = _DocnameModifier
118+
doc = _DocnameModifier
119119
desc = _DescModifier
120120

121121
qltest = _Namespace(

swift/codegen/lib/schema/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Kind(Enum):
3636
type: Optional[str] = None
3737
is_child: bool = False
3838
pragmas: List[str] = field(default_factory=list)
39-
doc_name: Optional[str] = None
39+
doc: Optional[str] = None
4040
description: List[str] = field(default_factory=list)
4141

4242
@property

swift/codegen/templates/ql_class.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ module Generated {
118118
{{#is_repeated}}
119119

120120
/**
121-
* Gets any of the {{doc_name_plural}}.
121+
* Gets any of the {{doc_plural}}.
122122
*/
123123
final {{type}} {{indefinite_getter}}() {
124124
result = {{getter}}(_)
125125
}
126126
{{^is_optional}}
127127

128128
/**
129-
* Gets the number of {{doc_name_plural}}.
129+
* Gets the number of {{doc_plural}}.
130130
*/
131131
final int getNumberOf{{plural}}() {
132132
result = count({{indefinite_getter}}())
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Gets the {{#is_repeated}}`index`th {{/is_repeated}}{{doc_name}}{{#is_repeated}} (0-based){{/is_repeated}}{{#is_optional}}, if it exists{{/is_optional}}.
1+
Gets the {{#is_repeated}}`index`th {{/is_repeated}}{{doc}}{{#is_repeated}} (0-based){{/is_repeated}}{{#is_optional}}, if it exists{{/is_optional}}.

swift/codegen/test/test_qlgen.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def test_single_property(generate_classes):
190190
ql.Class(name="MyObject", final=True,
191191
properties=[
192192
ql.Property(singular="Foo", type="bar", tablename="my_objects",
193-
tableparams=["this", "result"], doc_name="foo"),
193+
tableparams=["this", "result"], doc="foo"),
194194
])),
195195
}
196196

@@ -215,31 +215,31 @@ def test_children(generate_classes):
215215
ql.Class(name="MyObject", final=True,
216216
properties=[
217217
ql.Property(singular="A", type="int", tablename="my_objects",
218-
tableparams=["this", "result", "_"], doc_name="a"),
218+
tableparams=["this", "result", "_"], doc="a"),
219219
ql.Property(singular="Child1", type="int", tablename="my_objects",
220220
tableparams=["this", "_", "result"], prev_child="",
221-
doc_name="child 1"),
221+
doc="child 1"),
222222
ql.Property(singular="B", plural="Bs", type="int",
223223
tablename="my_object_bs",
224224
tableparams=["this", "index", "result"],
225-
doc_name="b", doc_name_plural="bs"),
225+
doc="b", doc_plural="bs"),
226226
ql.Property(singular="Child", plural="Children", type="int",
227227
tablename="my_object_children",
228228
tableparams=["this", "index", "result"], prev_child="Child1",
229-
doc_name="child", doc_name_plural="children"),
229+
doc="child", doc_plural="children"),
230230
ql.Property(singular="C", type="int", tablename="my_object_cs",
231-
tableparams=["this", "result"], is_optional=True, doc_name="c"),
231+
tableparams=["this", "result"], is_optional=True, doc="c"),
232232
ql.Property(singular="Child3", type="int", tablename="my_object_child_3s",
233233
tableparams=["this", "result"], is_optional=True,
234-
prev_child="Child", doc_name="child 3"),
234+
prev_child="Child", doc="child 3"),
235235
ql.Property(singular="D", plural="Ds", type="int",
236236
tablename="my_object_ds",
237237
tableparams=["this", "index", "result"], is_optional=True,
238-
doc_name="d", doc_name_plural="ds"),
238+
doc="d", doc_plural="ds"),
239239
ql.Property(singular="Child4", plural="Child4s", type="int",
240240
tablename="my_object_child_4s",
241241
tableparams=["this", "index", "result"], is_optional=True,
242-
prev_child="Child3", doc_name="child 4", doc_name_plural="child 4s"),
242+
prev_child="Child3", doc="child 4", doc_plural="child 4s"),
243243
])),
244244
}
245245

@@ -256,11 +256,11 @@ def test_single_properties(generate_classes):
256256
ql.Class(name="MyObject", final=True,
257257
properties=[
258258
ql.Property(singular="One", type="x", tablename="my_objects",
259-
tableparams=["this", "result", "_", "_"], doc_name="one"),
259+
tableparams=["this", "result", "_", "_"], doc="one"),
260260
ql.Property(singular="Two", type="y", tablename="my_objects",
261-
tableparams=["this", "_", "result", "_"], doc_name="two"),
261+
tableparams=["this", "_", "result", "_"], doc="two"),
262262
ql.Property(singular="Three", type="z", tablename="my_objects",
263-
tableparams=["this", "_", "_", "result"], doc_name="three"),
263+
tableparams=["this", "_", "_", "result"], doc="three"),
264264
])),
265265
}
266266

@@ -278,7 +278,7 @@ def test_optional_property(generate_classes, is_child, prev_child):
278278
ql.Class(name="MyObject", final=True, properties=[
279279
ql.Property(singular="Foo", type="bar", tablename="my_object_foos",
280280
tableparams=["this", "result"],
281-
is_optional=True, prev_child=prev_child, doc_name="foo"),
281+
is_optional=True, prev_child=prev_child, doc="foo"),
282282
])),
283283
}
284284

@@ -296,7 +296,7 @@ def test_repeated_property(generate_classes, is_child, prev_child):
296296
ql.Class(name="MyObject", final=True, properties=[
297297
ql.Property(singular="Foo", plural="Foos", type="bar", tablename="my_object_foos",
298298
tableparams=["this", "index", "result"], prev_child=prev_child,
299-
doc_name="foo", doc_name_plural="foos"),
299+
doc="foo", doc_plural="foos"),
300300
])),
301301
}
302302

@@ -315,7 +315,7 @@ def test_repeated_optional_property(generate_classes, is_child, prev_child):
315315
ql.Class(name="MyObject", final=True, properties=[
316316
ql.Property(singular="Foo", plural="Foos", type="bar", tablename="my_object_foos",
317317
tableparams=["this", "index", "result"], is_optional=True,
318-
prev_child=prev_child, doc_name="foo", doc_name_plural="foos"),
318+
prev_child=prev_child, doc="foo", doc_plural="foos"),
319319
])),
320320
}
321321

@@ -346,7 +346,7 @@ def test_single_class_property(generate_classes, is_child, prev_child):
346346
ql.Property(singular="Foo", type="Bar", tablename="my_objects",
347347
tableparams=[
348348
"this", "result"],
349-
prev_child=prev_child, doc_name="foo"),
349+
prev_child=prev_child, doc="foo"),
350350
],
351351
)),
352352
"Bar.qll": (ql.Stub(name="Bar", base_import=gen_import_prefix + "Bar"),
@@ -644,43 +644,43 @@ def test_property_description(generate_classes):
644644
ql.Class(name="MyObject", final=True,
645645
properties=[
646646
ql.Property(singular="Foo", type="bar", tablename="my_objects",
647-
tableparams=["this", "result"], doc_name="foo",
647+
tableparams=["this", "result"], doc="foo",
648648
description=description),
649649
])),
650650
}
651651

652652

653-
def test_property_doc_name_override(generate_classes):
653+
def test_property_doc_override(generate_classes):
654654
assert generate_classes([
655655
schema.Class("MyObject", properties=[
656-
schema.SingleProperty("foo", "bar", doc_name="baz")]),
656+
schema.SingleProperty("foo", "bar", doc="baz")]),
657657
]) == {
658658
"MyObject.qll": (ql.Stub(name="MyObject", base_import=gen_import_prefix + "MyObject"),
659659
ql.Class(name="MyObject", final=True,
660660
properties=[
661661
ql.Property(singular="Foo", type="bar", tablename="my_objects",
662-
tableparams=["this", "result"], doc_name="baz"),
662+
tableparams=["this", "result"], doc="baz"),
663663
])),
664664
}
665665

666666

667-
def test_repeated_property_doc_name_override(generate_classes):
667+
def test_repeated_property_doc_override(generate_classes):
668668
assert generate_classes([
669669
schema.Class("MyObject", properties=[
670-
schema.RepeatedProperty("x", "int", doc_name="children"),
671-
schema.RepeatedOptionalProperty("y", "int", doc_name="child")]),
670+
schema.RepeatedProperty("x", "int", doc="children"),
671+
schema.RepeatedOptionalProperty("y", "int", doc="child")]),
672672
]) == {
673673
"MyObject.qll": (ql.Stub(name="MyObject", base_import=gen_import_prefix + "MyObject"),
674674
ql.Class(name="MyObject", final=True,
675675
properties=[
676676
ql.Property(singular="X", plural="Xes", type="int",
677677
tablename="my_object_xes",
678678
tableparams=["this", "index", "result"],
679-
doc_name="child", doc_name_plural="children"),
679+
doc="child", doc_plural="children"),
680680
ql.Property(singular="Y", plural="Ys", type="int",
681681
tablename="my_object_ies", is_optional=True,
682682
tableparams=["this", "index", "result"],
683-
doc_name="child", doc_name_plural="children"),
683+
doc="child", doc_plural="children"),
684684
])),
685685
}
686686

swift/codegen/test/test_schema.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,24 +542,24 @@ class A:
542542
}
543543

544544

545-
def test_property_doc_name_override():
545+
def test_property_doc_override():
546546
@schema.load
547547
class data:
548548
class A:
549-
x: int | defs.docname("y")
549+
x: int | defs.doc("y")
550550

551551
assert data.classes == {
552552
'A': schema.Class('A', properties=[
553-
schema.SingleProperty('x', 'int', doc_name="y")]),
553+
schema.SingleProperty('x', 'int', doc="y")]),
554554
}
555555

556556

557-
def test_predicate_cannot_have_doc_name_override():
557+
def test_predicate_cannot_have_doc_override():
558558
with pytest.raises(schema.Error):
559559
@schema.load
560560
class data:
561561
class A:
562-
x: defs.predicate | defs.docname("y")
562+
x: defs.predicate | defs.doc("y")
563563

564564

565565
if __name__ == '__main__':

swift/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ class FunctionType(AnyFunctionType):
904904

905905
class GenericFunctionType(AnyFunctionType):
906906
""" The type of a generic function with type parameters """
907-
generic_params: list["GenericTypeParamType"] | docname("generic parameters")
907+
generic_params: list["GenericTypeParamType"] | doc("generic parameters")
908908

909909
class GenericTypeParamType(SubstitutableType):
910910
pass

0 commit comments

Comments
 (0)