Skip to content

Commit a51512b

Browse files
committed
refactor: implement code review feedback
1 parent 9684f2e commit a51512b

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

src/mdformat/_cli.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -303,29 +303,14 @@ def make_arg_parser(
303303
plugin.add_cli_argument_group(group)
304304
for action in group._group_actions:
305305
action.dest = f"plugin.{plugin_id}.{action.dest}"
306-
if type(action) in {
307-
argparse._StoreTrueAction,
308-
argparse._StoreFalseAction,
309-
}:
306+
if not (action.default is None or action.default == argparse.SUPPRESS):
310307
import warnings
311308

312-
is_store_true = type(action) is argparse._StoreTrueAction
313-
plugin_name = (
314-
action.container.title
315-
if hasattr(action, "container")
316-
else str(plugin)
317-
)
318-
text = (
319-
f"For {action.option_strings} from {plugin_name},"
320-
" the default will always override a value configured"
321-
" in TOML. To resolve, replace `.add_argument(...,"
322-
f' action="store_{str(is_store_true).lower()}")` with'
323-
f' `(..., action="store_const", const={is_store_true})`'
324-
)
309+
text = f"The argument default for {action.option_strings} from the '{plugin_id}' plugin, will always override any value configured in TOML. The only supported CLI defaults are `None` or `argparse.SUPPRESS`" # noqa: E501
325310
plugin_file, plugin_line = get_source_file_and_line(action)
326311
warnings.warn_explicit(
327312
text,
328-
UserWarning,
313+
DeprecationWarning,
329314
filename=plugin_file,
330315
lineno=plugin_line,
331316
)

tests/test_plugins.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,18 +284,20 @@ def update_mdit(mdit: MarkdownIt):
284284
def add_cli_argument_group(group: argparse._ArgumentGroup) -> None:
285285
group.add_argument("--store-true", action="store_true")
286286
group.add_argument("--store-false", action="store_false")
287+
group.add_argument("--store-zero", default=0)
287288
group.add_argument("--store-const", action="store_const", const=True)
288289

289290
monkeypatch.setitem(PARSER_EXTENSIONS, "table", ExamplePluginWithStoreTrue)
290291
file_path = tmp_path / "test_markdown.md"
291292
file_path.touch()
292293

293294
with patch.object(MDRenderer, "render", return_value=""):
294-
with pytest.warns(UserWarning) as warnings:
295+
with pytest.warns(DeprecationWarning) as warnings:
295296
assert run([str(file_path)]) == 0
296297

297-
assert "store_true" in str(warnings.pop().message)
298-
assert "store_false" in str(warnings.pop().message)
298+
assert "--store-true" in str(warnings.pop().message)
299+
assert "--store-false" in str(warnings.pop().message)
300+
assert "--store-zero" in str(warnings.pop().message)
299301
assert len(warnings) == 0
300302

301303

0 commit comments

Comments
 (0)