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 Base.fieldtypes. #29600

Merged
merged 1 commit into from Nov 1, 2018

Conversation

6 participants
@tpapp
Copy link
Contributor

commented Oct 11, 2018

Add Base.fieldtypes. Cf fieldnames vs fieldname.

Fixes #24312, but is more general. See discussion there.

@StefanKarpinski

This comment has been minimized.

Copy link
Member

commented Oct 11, 2018

Should we have fieldtype(T, i) to get the type of a single field? Either in addition to or instead of this API which returns all of the field types.

@tpapp

This comment has been minimized.

Copy link
Contributor Author

commented Oct 11, 2018

@StefanKarpinski: don't we already have the builtin fieldtype(T, i) which basically does that?

@StefanKarpinski

This comment has been minimized.

Copy link
Member

commented Oct 11, 2018

Oh, right. Forgot about that—carry on.

@KristofferC KristofferC added the triage label Oct 11, 2018

@@ -262,6 +262,10 @@ tlayout = TLayout(5,7,11)
@test fieldtype((NamedTuple{(:a,:b),T} where T<:Tuple{Vararg{Integer}}), 2) === Integer
@test_throws BoundsError fieldtype(NamedTuple{(:a,:b)}, 3)

@test fieldtypes(NamedTuple{(:a,:b)}) == (Any, Any)
@test fieldtypes((NamedTuple{T,Tuple{Int,String}} where T)) === (Int, String)
@test fieldtypes(TLayout) === (Int8, Int16, Int32)

This comment has been minimized.

Copy link
@martinholters

martinholters Oct 11, 2018

Member

Can we test that these are inferred correctly? Or are they inferred as Tuple{Datatype,Datatype,...}?

This comment has been minimized.

Copy link
@tpapp

tpapp Oct 12, 2018

Author Contributor

Would adding an @inferred be a satisfactory test? Because that passes.

This comment has been minimized.

Copy link
@nalimilan

nalimilan Oct 13, 2018

Contributor

AFAICT @inferred won't work since typeof((Int8, Int16, Int32)) == Tuple{DataType,DataType,DataType}.

This comment has been minimized.

Copy link
@tpapp

tpapp Oct 13, 2018

Author Contributor

Then I am not sure how to do what @martinholters is asking for, but given an explanation or an example (eg some test in Base) I would be happy to learn it and add those tests.

@tpapp

This comment has been minimized.

Copy link
Contributor Author

commented Oct 12, 2018

Also, this PR would allow replacing a couple of T.parameter with fieldtypes(T) in Base, should I do that?

@JeffBezanson

This comment has been minimized.

Copy link
Member

commented Nov 1, 2018

No, I would leave those alone unless it fixes an actual problem.

@JeffBezanson JeffBezanson merged commit 6d416e4 into JuliaLang:master Nov 1, 2018

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
julia freebsd ci Build done
Details

@JeffBezanson JeffBezanson removed the triage label Nov 1, 2018

fredrikekre added a commit that referenced this pull request Dec 5, 2018

Addition of NEWS and compat admonitions for important
changes between Julia 1.0 and 1.1, including:

- Custom .css-style for compat admonitions.

- Information about compat annotations to CONTRIBUTING.md.

- NEWS.md entry for PRs #30090, #30035, #30022, #29978,
  #29969, #29858, #29845, #29754, #29638, #29636, #29615,
  #29600, #29506, #29469, #29316, #29259, #29178, #29153,
  #29033, #28902, #28761, #28745, #28708, #28696, #29997,
  #28790, #29092, #29108, #29782

- Compat annotation for PRs #30090, #30013, #29978,
  #29890, #29858, #29827, #29754, #29679, #29636, #29623,
  #29600, #29440, #29316, #29259, #29178, #29157, #29153,
  #29033, #28902, #28878, #28761, #28708, #28156, #29733,
  #29670, #29997, #28790, #29092, #29108, #29782, #25278

- Documentation for broadcasting CartesianIndices (#30230).
- Documentation for Base.julia_cmd().
- Documentation for colon constructor of CartesianIndices (#29440).
- Documentation for ^(::Matrix, ::Number) and ^(::Number, ::Matrix).

- Run NEWS-update.jl.

Co-authored-by: Morten Piibeleht <morten.piibeleht@gmail.com>
Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>

fredrikekre added a commit that referenced this pull request Dec 5, 2018

Addition of NEWS and compat admonitions for important
changes between Julia 1.0 and 1.1, including:

- Custom .css-style for compat admonitions.

- Information about compat annotations to CONTRIBUTING.md.

- NEWS.md entry for PRs #30090, #30035, #30022, #29978,
  #29969, #29858, #29845, #29754, #29638, #29636, #29615,
  #29600, #29506, #29469, #29316, #29259, #29178, #29153,
  #29033, #28902, #28761, #28745, #28708, #28696, #29997,
  #28790, #29092, #29108, #29782

- Compat annotation for PRs #30090, #30013, #29978,
  #29890, #29858, #29827, #29754, #29679, #29636, #29623,
  #29600, #29440, #29316, #29259, #29178, #29157, #29153,
  #29033, #28902, #28878, #28761, #28708, #28156, #29733,
  #29670, #29997, #28790, #29092, #29108, #29782, #25278

- Documentation for broadcasting CartesianIndices (#30230).
- Documentation for Base.julia_cmd().
- Documentation for colon constructor of CartesianIndices (#29440).
- Documentation for ^(::Matrix, ::Number) and ^(::Number, ::Matrix).

- Run NEWS-update.jl.

Co-authored-by: Morten Piibeleht <morten.piibeleht@gmail.com>
Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>

fredrikekre added a commit that referenced this pull request Dec 5, 2018

Compat admonitions and NEWS for Julia 1.1 (#30230)
Addition of NEWS and compat admonitions for important changes between Julia 1.0 and 1.1, including:

- Custom .css-style for compat admonitions.

- Information about compat annotations to CONTRIBUTING.md.

- NEWS.md entry for PRs #30090, #30035, #30022, #29978,
  #29969, #29858, #29845, #29754, #29638, #29636, #29615,
  #29600, #29506, #29469, #29316, #29259, #29178, #29153,
  #29033, #28902, #28761, #28745, #28708, #28696, #29997,
  #28790, #29092, #29108, #29782

- Compat annotation for PRs #30090, #30013, #29978,
  #29890, #29858, #29827, #29754, #29679, #29636, #29623,
  #29600, #29440, #29316, #29259, #29178, #29157, #29153,
  #29033, #28902, #28878, #28761, #28708, #28156, #29733,
  #29670, #29997, #28790, #29092, #29108, #29782, #25278

- Documentation for broadcasting CartesianIndices (#30230).
- Documentation for Base.julia_cmd().
- Documentation for colon constructor of CartesianIndices (#29440).
- Documentation for ^(::Matrix, ::Number) and ^(::Number, ::Matrix).

- Run NEWS-update.jl.


Co-authored-by: Morten Piibeleht <morten.piibeleht@gmail.com>
Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>

@tpapp tpapp deleted the tpapp:tp/add-fieldtypes branch Jan 22, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.