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

Add support to multiple property pairs in sprint #39381

Merged
merged 6 commits into from
Feb 22, 2021
Merged

Add support to multiple property pairs in sprint #39381

merged 6 commits into from
Feb 22, 2021

Conversation

ronisbr
Copy link
Sponsor Member

@ronisbr ronisbr commented Jan 24, 2021

Sometimes it is required to pass multiple properties to IOContext in
sprint. For example, if we want to print with :compact and :limit
set to true. Currently, the only possible way to do this is creating an
IOContext using a dummy IOBuffer with those parameters. Hence, this
commit allows to pass a vector of pairs :key=>value to context
keyword of sprint so that we can easily set multiple properties.

This is not a breaking change, and no performance regression was
identified when using the previous function signatures.

@rfourquet rfourquet added the domain:display and printing Aesthetics and correctness of printed representations of objects. label Jan 28, 2021
@ronisbr
Copy link
Sponsor Member Author

ronisbr commented Feb 9, 2021

Bump!

@simeonschaub
Copy link
Member

I think this should have a compat note in the docstring, but otherwise looks good to me.

@ronisbr
Copy link
Sponsor Member Author

ronisbr commented Feb 11, 2021

@simeonschaub Done! I think I just need to add the information to NEWS.md, but I will wait for approval to avoid multiple rebases.

@ronisbr
Copy link
Sponsor Member Author

ronisbr commented Feb 19, 2021

Bump!

Copy link
Member

@rfourquet rfourquet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

base/strings/io.jl Outdated Show resolved Hide resolved
base/strings/io.jl Outdated Show resolved Hide resolved
@rfourquet rfourquet added the needs news A NEWS entry is required for this change label Feb 20, 2021
ronisbr and others added 6 commits February 21, 2021 19:26
Sometimes it is required to pass multiple properties to `IOContext` in
`sprint`. For example, if we want to print with `:compact` and `:limit`
set to true. Currently, the only possible way to do this is creating an
`IOContext` using a dummy `IOBuffer` with those parameters. Hence, this
commit allows to pass a vector of pairs `:key=>value` to `context`
keyword of `sprint` so that we can easily set multiple properties.

This is not a breaking change, and no performance regression was
identified when using the previous function signatures.
Co-authored-by: Rafael Fourquet <fourquet.rafael@gmail.com>
@ronisbr
Copy link
Sponsor Member Author

ronisbr commented Feb 22, 2021

Done @rfourquet ! Thanks for the review.

@ronisbr ronisbr removed the needs news A NEWS entry is required for this change label Feb 22, 2021
@simeonschaub simeonschaub merged commit 909c7f3 into JuliaLang:master Feb 22, 2021
@ronisbr ronisbr deleted the sprint_context branch February 22, 2021 11:04
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this pull request May 4, 2021
* Add support to multiple property pairs in sprint

Sometimes it is required to pass multiple properties to `IOContext` in
`sprint`. For example, if we want to print with `:compact` and `:limit`
set to true. Currently, the only possible way to do this is creating an
`IOContext` using a dummy `IOBuffer` with those parameters. Hence, this
commit allows to pass a vector of pairs `:key=>value` to `context`
keyword of `sprint` so that we can easily set multiple properties.

This is not a breaking change, and no performance regression was
identified when using the previous function signatures.

* Add compat annotation to sprint

* Update base/strings/io.jl

Co-authored-by: Rafael Fourquet <fourquet.rafael@gmail.com>

* Update sprint docstring

* Update NEWS.md

* Move NEWS.md entry to the correct place

Co-authored-by: Rafael Fourquet <fourquet.rafael@gmail.com>
antoine-levitt pushed a commit to antoine-levitt/julia that referenced this pull request May 9, 2021
* Add support to multiple property pairs in sprint

Sometimes it is required to pass multiple properties to `IOContext` in
`sprint`. For example, if we want to print with `:compact` and `:limit`
set to true. Currently, the only possible way to do this is creating an
`IOContext` using a dummy `IOBuffer` with those parameters. Hence, this
commit allows to pass a vector of pairs `:key=>value` to `context`
keyword of `sprint` so that we can easily set multiple properties.

This is not a breaking change, and no performance regression was
identified when using the previous function signatures.

* Add compat annotation to sprint

* Update base/strings/io.jl

Co-authored-by: Rafael Fourquet <fourquet.rafael@gmail.com>

* Update sprint docstring

* Update NEWS.md

* Move NEWS.md entry to the correct place

Co-authored-by: Rafael Fourquet <fourquet.rafael@gmail.com>
@o314
Copy link
Contributor

o314 commented Jan 20, 2022

Hi there. A pity that namedtuple support has not been implemented in addition.

# done
sprint(show, v; context=(:compact=>true, :limit=>true))

# still todo
sprint(show, v; context=(; compact=true, limit=true)) # more julian IMHO

I'am a bit short on time those days to pr it

EDITED
idem for repr; tips for impl:

if context isa NamedTuple
    f(IOContext(s, pairs(context)...), args...)

should be enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants