Skip to content

Commit cd3368b

Browse files
committed
Add option for listing all warning tags
1 parent 43a2618 commit cd3368b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

py/dml/dmlc.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,27 @@ def flush_porting_log(tmpfile, porting_filename):
261261
# (so retrying compile will succeed)
262262
os.rmdir(lockfile)
263263

264+
class HelpAction(argparse.Action):
265+
def __init__(self, option_strings, dest, **kwargs):
266+
super().__init__(option_strings, dest, nargs=0, **kwargs)
267+
268+
def __call__(self, parser, namespace, values, option_string=None):
269+
self.print_help()
270+
parser.exit()
271+
272+
class WarnHelpAction(HelpAction):
273+
def print_help(self):
274+
print('''Tags accepted by --warn and --nowarn:''')
275+
by_ignored = {True: [], False: []}
276+
for tag in sorted(messages.warnings):
277+
by_ignored[warning_is_ignored(tag)].append(tag)
278+
print(' Enabled by default:')
279+
for tag in by_ignored[False]:
280+
print(f' {tag}')
281+
print(' Disabled by default:')
282+
for tag in by_ignored[True]:
283+
print(f' {tag}')
284+
264285
def main(argv):
265286
# DML files must be utf8, but are generally opened without specifying
266287
# the 'encoding' arg. This works only if utf8_mode is enabled.
@@ -357,6 +378,8 @@ def main(argv):
357378
default=[],
358379
help='disable warning TAG')
359380

381+
parser.add_argument('--help-warn', action=WarnHelpAction,
382+
help='List warning tags available for --warn/--nowarn')
360383
# <dt>--werror</dt>
361384
# <dd>Turn all warnings into errors.</dd>
362385
parser.add_argument('--werror', action='store_true',

py/dml/messages.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,3 +2466,7 @@ class PINT1(PortingMessage):
24662466
types, then the value of the variable becomes 1, whereas for
24672467
`int1` in DML 1.4 the value is -1."""
24682468
fmt = "Change int1 to uint1"
2469+
2470+
warnings = {name: cls for (name, cls) in globals().items()
2471+
if isinstance(cls, type) and issubclass(cls, DMLWarning)
2472+
and cls is not DMLWarning}

0 commit comments

Comments
 (0)