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

Keyword argument docs for read are misleading #17070

Closed
tkelman opened this issue Jun 23, 2016 · 2 comments
Closed

Keyword argument docs for read are misleading #17070

tkelman opened this issue Jun 23, 2016 · 2 comments
Labels
docs This change adds or pertains to documentation good first issue Indicates a good issue for first-time contributors to Julia io Involving the I/O subsystem: libuv, read, write, etc.

Comments

@tkelman
Copy link
Contributor

tkelman commented Jun 23, 2016

This is via @aviks, we were looking at this in the morning:

help?> read
search: read read! readdlm readdir readcsv readall readlink readline readuntil readlines readchomp

  read(stream::IO, T)

  Read a single value of type T from stream, in canonical binary representation.

  read(stream::IO, T, dims)

  Read a series of values of type T from stream, in canonical binary representation. dims is either
  a tuple or a series of integer arguments specifying the size of the Array{T} to return.

  read(filename::AbstractString, args...)

  Open a file and read its contents. args is passed to read: this is equivalent to open(io->read(io,
  args...), filename).

  read(stream::IO, nb=typemax(Int); all=true)

  Read at most nb bytes from stream, returning a Vector{UInt8} of the bytes read.

  If all is true (the default), this function will block repeatedly trying to read all requested
  bytes, until an error or end-of-file occurs. If all is false, at most one read call is performed,
  and the amount of data returned is device-dependent. Note that not all stream types support the
  all option.

julia> s = TCPSocket()
TCPSocket(init, 0 bytes waiting)

julia> read(s, 10; all=true)
ERROR: MethodError: no method matching (::Base.#kw##read)(::Array{Any,1}, ::Base.#read, ::TCPSocket, ::Int64)
Closest candidates are:
  #read(::Array{Any,1}, ::Base.#read, ::IOStream, ::Integer)
 in eval(::Module, ::Any) at .\boot.jl:231
 in macro expansion at .\REPL.jl:92 [inlined]
 in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at .\event.jl:46

The all keyword argument is actually only implemented for IOStream, not all subtypes of IO.

@tkelman tkelman added docs This change adds or pertains to documentation io Involving the I/O subsystem: libuv, read, write, etc. labels Jun 23, 2016
@kshyatt kshyatt added the good first issue Indicates a good issue for first-time contributors to Julia label Jun 27, 2016
kshyatt added a commit that referenced this issue Aug 2, 2016
@tkelman tkelman closed this as completed in f1cf6d9 Aug 4, 2016
tkelman added a commit that referenced this issue Aug 4, 2016
Fix #17070, move docs out of HelpDB too.
mfasi pushed a commit to mfasi/julia that referenced this issue Sep 5, 2016
…e docs out of HelpDB too.

Fixed the type signatures. Made `nb` reflect what's actually in the
code.
@samoconnor
Copy link
Contributor

I think this is more than a doc issue.

The doc for read(s::IO, nb=typemax(Int)) says "Read at most nb bytes from s ...".

This is inconsistent with the default value of the all= option: read(s::IOStream, nb::Integer; all=true).

Currently, if I have x::IO and I want to read at most nb bytes, but not wait for more, I have to do this:

v = x isa IOStream ? read(x, 7; all=false) : read(x, 7)

Otherwise, the code will run nicely until the day someone passes in an IOStream, at which point it will hang forever.

Related: #24526

@samoconnor
Copy link
Contributor

Should this be reopened?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation good first issue Indicates a good issue for first-time contributors to Julia io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

No branches or pull requests

3 participants