Comments (8)
Lines 568 to 585 in cb9b00d
from julia.
I believe (but you can try testing this) taht the design and implementation of NamedTuple required that there was no type-assert here, as it relies on Type{T} elements being ignored. But there is not really a bug with it returning a value when it could have errored, and certainly not a correctness issue.
from julia.
Could you explain a bit more why the current behavior is correct? I'd usually expect that a call like T(x)
or convert(T, x)
would return a value of type T
(or throw), which doesn't happen in this case.
I'm interested in this problem because I'm looking into fixing #52993, so there I hit the exact same problem of what to do with UnionAll
types which subtype Tuple
. I think that maybe we could just throw if the type is UnionAll
?
from julia.
Some users want to write convert(Tuple{Type{T}}, (T,))
. That is somewhat badly written, but actually fairly reasonable to want to work. I don't see how that is related to the performance of the current implementation for _totuple(::Type{Tuple{Vararg{E}}}, itr, s...)
. And we cannot just start adding breaking errors in v1.x for cases that are not previously broken.
from julia.
I notice that the behavior when constructing a tuple from a tuple is inconsistent with the behavior when constructing a tuple from other iterators (xref #44179, where it was concluded that a type assertion is desirable):
julia> NTuple{2}((1, nothing))
(1, nothing)
julia> NTuple{2}([1, nothing])
ERROR: TypeError: in typeassert, expected Tuple{T, T} where T, got a value of type Tuple{Int64, Nothing}
Stacktrace:
[1] _totuple
@ ./tuple.jl:474 [inlined]
[2] (Tuple{T, T} where T)(itr::Vector{Union{Nothing, Int64}})
@ Base ./tuple.jl:455
[3] top-level scope
@ REPL[4]:1
julia> versioninfo()
Julia Version 1.11.0-DEV.1451
Commit f117a500ca9 (2024-02-01 15:38 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 × AMD Ryzen 3 5300U with Radeon Graphics
WORD_SIZE: 64
LLVM: libLLVM-16.0.6 (ORCJIT, znver2)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
I hope we could even out this inconsistency, in either direction?
from julia.
Would it be OK if we made the <:Tuple
constructors always assert the return type, but leave convert
as it is?
from julia.
Probably not. The inverse is possibly okay: convert
already uses type-assert afterwards so would probably be unimpacted, but NamedTuple and similar codes already assume the constructor does not type-assert
from julia.
And to be clear, a type-assert would probably be welcome for both, but needs to be done such that it doesn't break other code
from julia.
Related Issues (20)
- Round to Nearest Fraction HOT 3
- Bounds check outside loop affects loop performance
- `fieldcount` and `fieldtypes` mishandle some `Union` types HOT 3
- Regression in broadcast assignment to a `SlowSubArray` on nightly HOT 1
- Julia should have Pointers and Rust-like segmentation fault Analysis in compile time If ALLAH gives permission
- `Iterators.cycle`, `IteratorSize`: infinite but empty iterator HOT 1
- more source-build problems, with openblas now on CI HOT 9
- REPL does not have StyledStrings in its dependencies HOT 8
- Add error hint for `append(::Vector{String}, ::String)`
- make error message for Union{} arguments more accurate
- constructing tuples: some reasonable `Union` tuple type constructors throw
- constructing a tuple from an iterator may fail when it's not supposed to HOT 1
- return type infers worse than allowed by type assertion
- Add gerneric function for lazy `PermutedDimsArray` or `permutedims` keyword HOT 6
- `resize!(x,...)` not working after `y = x * A[1:1, :]` HOT 3
- [FR] provide a public API for accessing/mapping over `Union` components HOT 7
- Pkg precompile error with current `master` HOT 9
- CI test output `results.json` contains a lot of duplicate entries HOT 4
- CONTRIBUTING.md is unclear about standard library HOT 9
- Possible speedup in `searchsortedfirst` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia.