Skip to content

Add a similar method for Type{<:CodeUnits} #57826

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

Merged
merged 1 commit into from
Jul 2, 2025
Merged

Conversation

ararslan
Copy link
Member

Currently, similar(::CodeUnits) works as expected by going through the generic AbstractArray method. However, the fallback method hit by similar(::Type{<:CodeUnits}, dims) does not work, as it assumes the existence of a constructor that accepts an UndefInitializer. This can be made to work by defining a corresponding similar method that returns an Array.

One could make a case that this is a bugfix since it was arguably a bug that this method didn't work given that CodeUnits is an AbstractArray subtype and the other similar methods work. If anybody buys that argument, it could be nice to backport this; it came up in some internal code that uses Arrow.jl and JSON3.jl together.

@ararslan ararslan added the strings "Strings!" label Mar 18, 2025
@ararslan ararslan requested a review from KristofferC March 20, 2025 17:16
@ararslan
Copy link
Member Author

ararslan commented Apr 4, 2025

Bump

@ararslan ararslan force-pushed the aa/similar-codeunits branch from ce6998d to 299ed24 Compare April 16, 2025 16:33
@ararslan ararslan force-pushed the aa/similar-codeunits branch from 299ed24 to 621ab82 Compare May 16, 2025 00:06
Currently, `similar(::CodeUnits)` works as expected by going through the
generic `AbstractArray` method. However, the fallback method hit by
`similar(::Type{<:CodeUnits}, dims)` does not work, as it assumes the
existence of a constructor that accepts an `UndefInitializer`. This can
be made to work by defining a corresponding method that returns an
`Array`.
@ararslan ararslan force-pushed the aa/similar-codeunits branch from 621ab82 to 7c1322b Compare July 1, 2025 17:57
@ararslan
Copy link
Member Author

ararslan commented Jul 2, 2025

@mbauman, do you think this could/should be backported? It was arguably a bug that this method didn't work given that CodeUnits <: AbstractArray and the other similar methods work.

@mbauman mbauman added backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 backport 1.12 Change should be backported to release-1.12 labels Jul 2, 2025
@mbauman mbauman merged commit 8e524c7 into master Jul 2, 2025
10 checks passed
@mbauman mbauman deleted the aa/similar-codeunits branch July 2, 2025 17:46
@ararslan
Copy link
Member Author

ararslan commented Jul 2, 2025

I'll take the application of those labels as a yes then. 😄 Thanks!

KristofferC pushed a commit that referenced this pull request Jul 3, 2025
Currently, `similar(::CodeUnits)` works as expected by going through the
generic `AbstractArray` method. However, the fallback method hit by
`similar(::Type{<:CodeUnits}, dims)` does not work, as it assumes the
existence of a constructor that accepts an `UndefInitializer`. This can
be made to work by defining a corresponding `similar` method that
returns an `Array`.

One could make a case that this is a bugfix since it was arguably a bug
that this method didn't work given that `CodeUnits` is an
`AbstractArray` subtype and the other `similar` methods work. If anybody
buys that argument, it could be nice to backport this; it came up in
some internal code that uses Arrow.jl and JSON3.jl together.

(cherry picked from commit 8e524c7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 backport 1.12 Change should be backported to release-1.12 strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants