Skip to content

Commit 7935320

Browse files
sethfitzvcschapp
authored andcommitted
Attach docstrings to NewTypes at runtime
Bare triple-quoted strings after NewType assignments are expression statements that Python never attaches to the NewType object, leaving __doc__ as None. Convert each to an explicit __doc__ assignment so codegen and introspection tools can read them at runtime. Same pattern DocumentedEnum uses for enum member docs.
1 parent 709b6c2 commit 7935320

5 files changed

Lines changed: 22 additions & 22 deletions

File tree

packages/overture-schema-core/src/overture/schema/core/names.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
Field(json_schema_extra={"additionalProperties": False}),
111111
],
112112
)
113-
"""A mapping from language to the most commonly used or recognized name in that language."""
113+
CommonNames.__doc__ = """A mapping from language to the most commonly used or recognized name in that language."""
114114

115115

116116
class NameVariant(str, DocumentedEnum):

packages/overture-schema-core/src/overture/schema/core/scoping/opening_hours.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
),
1616
],
1717
)
18-
"""
18+
OpeningHours.__doc__ = """
1919
Time span or time spans during which something is open or active, specified in the OpenStreetMap
2020
opening hours specification: https://wiki.openstreetmap.org/wiki/Key:opening_hours/specification.
2121
"""

packages/overture-schema-system/src/overture/schema/system/primitive/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,71 +24,71 @@
2424
)
2525

2626
uint8 = NewType("uint8", Annotated[int, Field(ge=0, le=255)]) # type: ignore [type-arg]
27-
"""
27+
uint8.__doc__ = """
2828
Portable 8-bit unsigned integer.
2929
3030
This is an `int` at runtime, but using `uint8` for Pydantic model fields instead of `int` makes them
3131
portable across different serialization and validation platforms.
3232
"""
3333

3434
uint16 = NewType("uint16", Annotated[int, Field(ge=0, le=65535)]) # type: ignore[type-arg]
35-
"""
35+
uint16.__doc__ = """
3636
Portable 16-bit unsigned integer.
3737
3838
This is an `int` at runtime, but using `uint16` for Pydantic model fields instead of `int` makes
3939
them portable across different serialization and validation platforms.
4040
"""
4141

4242
uint32 = NewType("uint32", Annotated[int, Field(ge=0, le=4294967295)]) # type: ignore[type-arg]
43-
"""
43+
uint32.__doc__ = """
4444
Portable 32-bit unsigned integer.
4545
4646
This is an `int` at runtime, but using `uint32` for Pydantic model fields instead of `int` makes
4747
them portable across different serialization and validation platforms.
4848
"""
4949

5050
int8 = NewType("int8", Annotated[int, Field(ge=-128, le=127)]) # type: ignore[type-arg]
51-
"""
51+
int8.__doc__ = """
5252
Portable 8-bit signed integer.
5353
5454
This is an `int` at runtime, but using `int8` for Pydantic model fields instead of `int` makes them
5555
portable across different serialization and validation platforms.
5656
"""
5757

5858
int16 = NewType("int16", Annotated[int, Field(ge=-32768, le=32767)]) # type: ignore[type-arg]
59-
"""
59+
int16.__doc__ = """
6060
Portable 16-bit signed integer.
6161
6262
This is an `int` at runtime, but using `int16` for Pydantic model fields instead of `int` makes them
6363
portable across different serialization and validation platforms.
6464
"""
6565

6666
int32 = NewType("int32", Annotated[int, Field(ge=-(2**31), le=2**31 - 1)]) # type: ignore[type-arg]
67-
"""
67+
int32.__doc__ = """
6868
Portable 32-bit signed integer.
6969
7070
This is an `int` at runtime, but using `int32` for Pydantic model fields instead of `int` makes them
7171
portable across different serialization and validation platforms.
7272
"""
7373

7474
int64 = NewType("int64", Annotated[int, Field(ge=-(2**63), le=2**63 - 1)]) # type: ignore[type-arg]
75-
"""
75+
int64.__doc__ = """
7676
Portable 64-bit signed integer.
7777
7878
This is an `int` at runtime, but using `int64` for Pydantic model fields instead of `int` makes them
7979
portable across different serialization and validation platforms.
8080
"""
8181

8282
float32 = NewType("float32", float) # type: ignore[type-arg]
83-
"""
83+
float32.__doc__ = """
8484
Portable IEEE 32-bit floating point number.
8585
8686
This is a `float` at runtime, but using `float32` for Pydantic model fields instead of `float` makes
8787
them portable across different serialization and validation platforms.
8888
"""
8989

9090
float64 = NewType("float64", float) # type: ignore[type-arg]
91-
"""
91+
float64.__doc__ = """
9292
Portable IEEE 64-bit floating point number.
9393
9494
This is a `float` at runtime, but using `float64` for Pydantic model fields instead of `float` makes

packages/overture-schema-system/src/overture/schema/system/ref/id.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
),
1919
],
2020
)
21-
"""
21+
Id.__doc__ = """
2222
A unique identifier.
2323
"""
2424

packages/overture-schema-system/src/overture/schema/system/string.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
Field(description="An ISO 3166-1 alpha-2 country code"),
3636
],
3737
) # type: ignore [type-arg]
38-
"""
38+
CountryCodeAlpha2.__doc__ = """
3939
An ISO-3166-1 alpha-2 country code.
4040
"""
4141

@@ -49,7 +49,7 @@
4949
),
5050
],
5151
) # type: ignore [type-arg]
52-
"""
52+
HexColor.__doc__ = """
5353
A color represented as an #RRGGBB or #RGB hexadecimal string.
5454
5555
For example:
@@ -67,7 +67,7 @@
6767
Field(description="A JSON Pointer (as described in RFC-6901)"),
6868
],
6969
) # type: ignore [type-arg]
70-
"""
70+
JsonPointer.__doc__ = """
7171
A JSON Pointer
7272
7373
As described in `the JSON Pointer specification, RFC-6901`_.
@@ -91,7 +91,7 @@
9191
),
9292
],
9393
) # type: ignore [type-arg]
94-
"""
94+
LanguageTag.__doc__ = """
9595
A BCP-47 language tag.
9696
9797
As described in `Tags for Identifying Languages, BCP-47`_.
@@ -114,7 +114,7 @@
114114
Field(description="A string that contains no whitespace characters"),
115115
],
116116
) # type: ignore [type-arg]
117-
"""
117+
NoWhitespaceString.__doc__ = """
118118
A string that contains no whitespace characters.
119119
"""
120120

@@ -124,7 +124,7 @@
124124
str, PhoneNumberConstraint(), Field(description="An international phone number")
125125
],
126126
) # type: ignore [type-arg]
127-
"""
127+
PhoneNumber.__doc__ = """
128128
An international phone number.
129129
"""
130130

@@ -136,12 +136,12 @@
136136
Field(description="An ISO 3166-2 principal subdivision code"),
137137
],
138138
) # type: ignore [type-arg]
139-
"""
139+
RegionCode.__doc__ = """
140140
An ISO 3166-2 principal subdivision code.
141141
"""
142142

143143
SnakeCaseString = NewType("SnakeCaseString", Annotated[str, SnakeCaseConstraint()])
144-
"""
144+
SnakeCaseString.__doc__ = """
145145
A string that looks like a snake case identifier, like a Python variable name (*e.g.*, `foo_bar`).
146146
"""
147147

@@ -155,7 +155,7 @@
155155
),
156156
],
157157
) # type: ignore [type-arg]
158-
"""
158+
StrippedString.__doc__ = """
159159
A string without leading or trailing whitespace.
160160
"""
161161

@@ -167,7 +167,7 @@
167167
Field(description="A wikidata ID, as found on https://www.wikidata.org/"),
168168
],
169169
) # type: ignore [type-arg]
170-
"""
170+
WikidataId.__doc__ = """
171171
A wikidata ID, as found on https://www.wikidata.org/.
172172
173173
- `"Q42"`

0 commit comments

Comments
 (0)