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

parse(Bool,"0") doesn't work #29980

Closed
favba opened this issue Nov 9, 2018 · 1 comment
Closed

parse(Bool,"0") doesn't work #29980

favba opened this issue Nov 9, 2018 · 1 comment

Comments

@favba
Copy link
Contributor

favba commented Nov 9, 2018

A common usage of parse (at least for me) is for reading configuration files.
For boolean flags we can encounter either a "true" string or a "1" (or "false" / "0").
But parsing of AbstractString to Bool with numeric text doesn't work (it works with Chars '0' and '1').

julia> a = split("test: 0")
2-element Array{SubString{String},1}:
 "test:"
 "0"

julia> parse(Bool,a[2])
ERROR: ArgumentError: invalid Bool representation: "0"
Stacktrace:
 [1] macro expansion at ./gcutils.jl:88 [inlined]
 [2] tryparse_internal(::Type{Bool}, ::SubString{String}, ::Int64, ::Int64, ::Int64, ::Bool) at ./parse.jl:188
 [3] #parse#333(::Nothing, ::Function, ::Type{Bool}, ::SubString{String}) at ./parse.jl:225
 [4] parse(::Type{Bool}, ::SubString{String}) at ./parse.jl:225
 [5] top-level scope at none:0

julia> versioninfo()
Julia Version 1.0.1
Commit 0d713926f8 (2018-09-29 19:05 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, broadwell)
Environment:
  JULIA_NUM_THREADS = 2

It is not difficult to work around this, but wouldn't it make sense to allow parsing of "0" and "1" (of any AbstractString type) to Bool?

@StefanKarpinski
Copy link
Member

Seems reasonable to me given that we have Bool <: Integer that one should be able to parse integer syntax for booleans.

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