Skip to content

Commit 7b1021f

Browse files
committed
pycodegen: idfields can never be None
1 parent 9fd211e commit 7b1021f

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

schema_salad/cpp_codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
# g++ versions older than version 10 may need "--std=c++2a" instead of "--std=c++20"
2020
"""
2121

22-
import re
2322
import os
23+
import re
2424
from typing import IO, Any, Optional, Union, cast
2525

2626
from . import _logger

schema_salad/metaschema.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,7 @@ class RecordField(Documented):
11621162
A field of a record.
11631163
"""
11641164

1165+
name: str
11651166
class_uri = "https://w3id.org/cwl/salad#RecordField"
11661167

11671168
def __init__(
@@ -1181,7 +1182,7 @@ def __init__(
11811182
else:
11821183
self.loadingOptions = LoadingOptions()
11831184
self.doc = doc
1184-
self.name = name
1185+
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
11851186
self.type_ = type_
11861187

11871188
def __eq__(self, other: Any) -> bool:
@@ -1636,6 +1637,7 @@ class EnumSchema(Saveable):
16361637
16371638
"""
16381639

1640+
name: str
16391641
class_uri = "https://w3id.org/cwl/salad#EnumSchema"
16401642

16411643
def __init__(
@@ -1654,7 +1656,7 @@ def __init__(
16541656
self.loadingOptions = loadingOptions
16551657
else:
16561658
self.loadingOptions = LoadingOptions()
1657-
self.name = name
1659+
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
16581660
self.symbols = symbols
16591661
self.type_ = type_
16601662

@@ -3479,6 +3481,7 @@ class SaladRecordField(RecordField):
34793481
A field of a record.
34803482
"""
34813483

3484+
name: str
34823485
class_uri = "https://w3id.org/cwl/salad#SaladRecordField"
34833486

34843487
def __init__(
@@ -3500,7 +3503,7 @@ def __init__(
35003503
else:
35013504
self.loadingOptions = LoadingOptions()
35023505
self.doc = doc
3503-
self.name = name
3506+
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
35043507
self.type_ = type_
35053508
self.jsonldPredicate = jsonldPredicate
35063509
self.default = default
@@ -3862,6 +3865,7 @@ def save(
38623865

38633866

38643867
class SaladRecordSchema(NamedType, RecordSchema, SchemaDefinedType):
3868+
name: str
38653869
class_uri = "https://w3id.org/cwl/salad#SaladRecordSchema"
38663870

38673871
def __init__(
@@ -3890,7 +3894,7 @@ def __init__(
38903894
self.loadingOptions = loadingOptions
38913895
else:
38923896
self.loadingOptions = LoadingOptions()
3893-
self.name = name
3897+
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
38943898
self.inVocab = inVocab
38953899
self.fields = fields
38963900
self.type_ = type_
@@ -4725,6 +4729,7 @@ class SaladEnumSchema(NamedType, EnumSchema, SchemaDefinedType):
47254729
47264730
"""
47274731

4732+
name: str
47284733
class_uri = "https://w3id.org/cwl/salad#SaladEnumSchema"
47294734

47304735
def __init__(
@@ -4751,7 +4756,7 @@ def __init__(
47514756
self.loadingOptions = loadingOptions
47524757
else:
47534758
self.loadingOptions = LoadingOptions()
4754-
self.name = name
4759+
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
47554760
self.inVocab = inVocab
47564761
self.symbols = symbols
47574762
self.type_ = type_
@@ -5468,6 +5473,7 @@ class SaladMapSchema(NamedType, MapSchema, SchemaDefinedType):
54685473
54695474
"""
54705475

5476+
name: str
54715477
class_uri = "https://w3id.org/cwl/salad#SaladMapSchema"
54725478

54735479
def __init__(
@@ -5493,7 +5499,7 @@ def __init__(
54935499
self.loadingOptions = loadingOptions
54945500
else:
54955501
self.loadingOptions = LoadingOptions()
5496-
self.name = name
5502+
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
54975503
self.inVocab = inVocab
54985504
self.type_ = type_
54995505
self.values = values
@@ -6155,6 +6161,7 @@ class SaladUnionSchema(NamedType, UnionSchema, DocType):
61556161
61566162
"""
61576163

6164+
name: str
61586165
class_uri = "https://w3id.org/cwl/salad#SaladUnionSchema"
61596166

61606167
def __init__(
@@ -6179,7 +6186,7 @@ def __init__(
61796186
self.loadingOptions = loadingOptions
61806187
else:
61816188
self.loadingOptions = LoadingOptions()
6182-
self.name = name
6189+
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
61836190
self.inVocab = inVocab
61846191
self.names = names
61856192
self.type_ = type_
@@ -6783,6 +6790,7 @@ class Documentation(NamedType, DocType):
67836790
67846791
"""
67856792

6793+
name: str
67866794
class_uri = "https://w3id.org/cwl/salad#Documentation"
67876795

67886796
def __init__(
@@ -6805,7 +6813,7 @@ def __init__(
68056813
self.loadingOptions = loadingOptions
68066814
else:
68076815
self.loadingOptions = LoadingOptions()
6808-
self.name = name
6816+
self.name = name if name is not None else "_:" + str(_uuid__.uuid4())
68096817
self.inVocab = inVocab
68106818
self.doc = doc
68116819
self.docParent = docParent

schema_salad/python_codegen.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ def begin_class(
164164
self.out.write(" pass\n\n\n")
165165
return
166166

167+
idfield_safe_name = self.safe_name(idfield) if idfield != "" else None
168+
if idfield_safe_name is not None:
169+
self.out.write(f" {idfield_safe_name}: str\n")
167170
self.out.write(f' class_uri = "{class_uri}"\n\n')
168171

169172
required_field_names = [f for f in field_names if f not in optional_fields]
@@ -203,6 +206,11 @@ def begin_class(
203206
""".format(
204207
classname
205208
)
209+
elif name == idfield_safe_name:
210+
field_inits += """ self.{0} = {0} if {0} is not None else "_:" + str(_uuid__.uuid4())
211+
""".format(
212+
self.safe_name(name)
213+
)
206214
else:
207215
field_inits += """ self.{0} = {0}
208216
""".format(

0 commit comments

Comments
 (0)