Skip to content

Commit 137c650

Browse files
committed
Various improvements to provisional.py
* abc.abstractproperty is deprecated. Fix by using property and abstractmethod instead. * Fix the type of the stable property. * Fix the property overriding syntax. * Start the text in the provisional features' docstrings with a blank line to make it render as a paragraph block. Previously the backticks would not render as typewriter text. * Fix type hints in parse_provisional. * Reformat the file using Black.
1 parent f095d46 commit 137c650

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

py/dml/provisional.py

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,30 @@
55
from . import logging
66
from . import messages
77

8+
89
class ProvisionalFeature(abc.ABC):
910
def tag(self) -> str:
1011
return self.__class__.__name__
1112

12-
@abc.abstractproperty
13-
def __doc__(self): pass
13+
@property
14+
@abc.abstractmethod
15+
def __doc__(self):
16+
pass
1417

15-
@abc.abstractproperty
16-
def short(self) -> str: pass
18+
@property
19+
@abc.abstractmethod
20+
def short(self) -> str:
21+
pass
1722

18-
@abc.abstractproperty
19-
def stable(self) -> str: pass
23+
@property
24+
@abc.abstractmethod
25+
def stable(self) -> bool:
26+
pass
2027

2128
# Whether the feature is included in 1.2 documentation
2229
dml12 = False
2330

31+
2432
# tag -> feature
2533
features: dict[str, ProvisionalFeature] = {}
2634

@@ -34,7 +42,8 @@ def feature(cls: type[ProvisionalFeature]):
3442

3543
@feature
3644
class explicit_param_decls(ProvisionalFeature):
37-
'''<a id="explicit_param_decls"/>
45+
"""<a id="explicit_param_decls"/>
46+
3847
This feature extends the DML syntax for parameter definitions to
3948
distinguish between an intent to declare a new parameter, and an intent to
4049
override an existing parameter (including when providing a definition
@@ -80,14 +89,21 @@ class explicit_param_decls(ProvisionalFeature):
8089
8190
Enabling the `explicit_param_decls` feature in a file only affects
8291
the parameter definitions specified in that file.
83-
'''
84-
short = "Require := syntax for defining new params"
85-
stable = True
92+
"""
93+
94+
@property
95+
def short(self) -> str:
96+
return "Require := syntax for defining new params"
97+
98+
@property
99+
def stable(self) -> bool:
100+
return True
86101

87102

88103
@feature
89104
class simics_util_vect(ProvisionalFeature):
90-
'''<a id="simics_util_vect"/>
105+
"""<a id="simics_util_vect"/>
106+
91107
This feature enables the `vect` type, based on the
92108
`VECT` macro from the Simics C API (`simics/util/vect.h`).
93109
@@ -130,18 +146,28 @@ class simics_util_vect(ProvisionalFeature):
130146
When the `simics_util_vect` feature is disabled, usage of `vect` is an
131147
error unless the [`experimental_vect` compatibility
132148
feature](deprecations-auto.html#experimental_vect) is enabled.
133-
'''
134-
short = "Allow vect syntax based on the VECT macro"
135-
stable = True
149+
"""
150+
151+
@property
152+
def short(self) -> str:
153+
return "Allow vect syntax based on the VECT macro"
154+
155+
@property
156+
def stable(self) -> bool:
157+
return True
158+
136159
dml12 = True
137160

161+
138162
def parse_provisional(
139-
provs: list[("Site", str)]) -> dict[ProvisionalFeature, "Site"]:
163+
provs: list[tuple[logging.Site, str]],
164+
) -> dict[ProvisionalFeature, logging.Site]:
140165
ret = {}
141-
for (site, name) in provs:
166+
for site, name in provs:
142167
if name in features:
143168
ret[features[name]] = site
144169
else:
145-
logging.report(messages.ENOPROV(
146-
site, name, ', '.join(sorted(features))))
170+
logging.report(
171+
messages.ENOPROV(site, name, ", ".join(sorted(features)))
172+
)
147173
return ret

0 commit comments

Comments
 (0)