Skip to content

Commit

Permalink
fix: Extraneous error message in usage output in Python 3.10
Browse files Browse the repository at this point in the history
* Fixes extraneous error message in usage output
  when using Python 3.10.
  Python 3.10's `argparse` usage messages were tweaked
  in a way that weren't fully backwards compatible
  with earlier Python versions.

closes #36
  • Loading branch information
trevorld committed Nov 25, 2021
1 parent 35fda94 commit 6b3e70c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: argparse
Type: Package
Title: Command Line Optional and Positional Argument Parser
Version: 2.1.2
Version: 2.1.3
Authors@R: c(person("Trevor L", "Davis", role=c("aut", "cre"), email="[email protected]"),
person("Allen", "Day", role="ctb", comment="Some documentation and examples ported from the getopt package."),
person("Python Software Foundation", role="ctb", comment="Some documentation from the optparse Python module."),
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
argparse 2.1.3
==============

* Prevents extraneous error message from being included in usage message
when using Python 3.10 (#36).
Thanks @dariober for bug report.

argparse 2.1.2
==============

Expand Down
2 changes: 1 addition & 1 deletion R/argparse.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Parser <- R6Class("Parser", # nolint
parse_args_output <- function(output) {
if (grepl("^usage:", output[1])) {
has_positional_arguments <- any(grepl("^positional arguments:", output))
has_optional_arguments <- any(grepl("^optional arguments:", output))
has_optional_arguments <- any(grepl("^optional arguments:|^options:", output))
if (has_positional_arguments || has_optional_arguments) {
.print_message_and_exit(output, "help requested:")
} else {
Expand Down
7 changes: 3 additions & 4 deletions tests/testthat/test-argparse.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test_that("print_help works as expected", {
skip_if_not(detects_python())
parser <- ArgumentParser(description = "Process some integers.")
expect_output(parser$print_help(), "usage:")
expect_output(parser$print_help(), "optional arguments:")
expect_output(parser$print_help(), "optional arguments:|options:")
expect_output(parser$print_help(), "Process some integers.")
expect_output(parser$print_usage(), "usage:")

Expand Down Expand Up @@ -324,7 +324,6 @@ test_that("Paths that quit()", {

help <- system2(cmd, c("scripts/test_help.R", "--help"),
stdout = TRUE, stderr = TRUE)
expect_equal(help,
c("usage: scripts/test_help.R [-h]", "", "optional arguments:",
" -h, --help show this help message and exit"))
expect_equal("usage: scripts/test_help.R [-h]", help[2])
expect_equal(" -h, --help show this help message and exit", help[5])
})

0 comments on commit 6b3e70c

Please sign in to comment.