-
Notifications
You must be signed in to change notification settings - Fork 41
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
fix fancy eltypes: use ConstructionBase.constructorof #241
Conversation
bump... |
I see the issue, but I'm not completely sure the solution is so straightforward. What worries me is that For example, julia> using ConstructionBase
julia> T = NamedTuple{(:a,), Tuple{Real}};
julia> constructorof(T)(1) isa T
false This turns out OK here, because In the long term, I feel like a better fix for the usecase in the testsuite would be to make sure that the type widening is done on the parameters, so that one gets a concrete eltype (eg |
I believe there were discussions about asserting that constructors always return the requested type
This would probably change the return type of regular |
Bump... I see this PR as an unambiguous improvement, even though not perfect (ie doesn't get rid of the whole create_instance function). Technically neither regular constructor T(...) nor constructorof(T)(...) guarantee that they return the T type. In practice, I would say the constructorof approach is more reliable: its docs say
Meanwhile, regular T(...) constructors can do whatever processing they want and take arbitrary arguments – not necessarily fields of the type. One doesn't even need to go outside of Base types to break StructArrays. This:
also doesn't work now, same as the example in this PR tests. But would work with constructorof(). |
Bump... |
Another bump |
Sorry for the very slow reaction time. I confess I'm hesitant to make fundamental changes such as this one to StructArrays (esp. since I have very limited time to dedicate to the package, so I wouldn't really be able to address any issues that could stem from this). OTOH, this does seem like a practical improvement, and the most important case of concrete element type is preserved, so it should be fine. I'll ask on the arrays Slack if there are strong opinions either way, otherwise I imagine it can be merged. |
Co-authored-by: Mason Protter <[email protected]>
bump! |
Rebased and merged in #280 |
An example of what gets fixed by this PR is added to runtests.jl: that test would fail before.