Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpredictable behavior when printing from inside custom parse_item function. #61

Open
jbdaley opened this issue May 17, 2018 · 4 comments

Comments

@jbdaley
Copy link

jbdaley commented May 17, 2018

On Julia 0.6 running ArgParse 0.5.0

using ArgParse
struct Foo end
function ArgParse.parse_item(::Type{Foo}, x::AbstractString)
  return Foo()
end
settings = ArgParseSettings(description = "Argparse Test")
@add_arg_table settings begin
  "--foo"
    arg_type = Foo
    required = true
    nargs = '+'
end
argsDict = parse_args(settings)

Reports too many arguments when running julia foo.jl --foo foo bar, but works fine if arg_type is replaced with String.

@carlobaldassi
Copy link
Owner

This is fixed on latest master. Until I release a new version (hopefully soon) you can Pkg.checkout("ArgParse").

@jbdaley
Copy link
Author

jbdaley commented May 18, 2018

I believe I over simplified my minimal example. I checkout out master 224ce77 to be sure. The following works when arg_type = Foo, but not when arg_type = Bar. The issue seems to actually be having print statements in parse_item methods.

using ArgParse
struct Foo end
function ArgParse.parse_item(::Type{Foo}, x::AbstractString)
  return Foo()
end
struct Bar end
function ArgParse.parse_item(::Type{Bar}, x::AbstractString)
  println()
  return Bar()
end
settings = ArgParseSettings(description = "Argparse Test")
@add_arg_table settings begin
  "--foo"
    arg_type = Bar
    required = true
    nargs = '+'
end
argsDict = parse_args(settings)

@carlobaldassi
Copy link
Owner

carlobaldassi commented May 18, 2018

I see. After a short investigation, this seems like a Julia bug (still present in 0.7), whereby printing anything to stdout/stderr while the parsing is proceeding is causing all sorts of unexpected behavior. I'll try to find a minimal example and I'll open an issue.

@carlobaldassi carlobaldassi reopened this May 18, 2018
@carlobaldassi
Copy link
Owner

this is the culprit: JuliaLang/julia#27168

@carlobaldassi carlobaldassi changed the title nargs='+' does not work when using custom types Unpredictable behavior when printing from inside custom parse_item function. May 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants