Skip to content

Does repr context officially allow multiple attributes? #58461

@bvdmitri

Description

@bvdmitri

From the documentation of the repr it is not entirely clear if the context keyword argument accepts multiple attributes. E.g. it says:

The optional keyword argument context can be set to :key=>value pair or an IO or IOContext object whose
attributes are used for the I/O stream passed to show.

What if I want to set multiple :key=>value pairs? This apparently works:

julia> repr(1; context=(:a => 1, :b => 2))
"1"

But is it the official way or it works by accident? For example this doesn't work

julia> repr(MIME"text/plain"(), 1; context=(:a => 1, :b => 2))
ERROR: MethodError: no method matching IOContext(::IOBuffer, ::Tuple{Pair{Symbol, Int64}, Pair{Symbol, Int64}})
The type `IOContext` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  IOContext(::IO, ::Pair)
   @ Base show.jl:333
  IOContext(::IO, ::Pair, Pair...)
   @ Base show.jl:413
  IOContext(::IO, ::Base.ImmutableDict{Symbol, Any})
   @ Base show.jl:316
  ...

Stacktrace:

Would be nice to clarify the usage of multiple attributes in the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    display and printingAesthetics and correctness of printed representations of objects.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions