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

allow narrowing of inherited types #535

Merged
merged 3 commits into from
May 18, 2022
Merged

allow narrowing of inherited types #535

merged 3 commits into from
May 18, 2022

Conversation

mr-c
Copy link
Member

@mr-c mr-c commented May 6, 2022

No description provided.

@codecov
Copy link

codecov bot commented May 6, 2022

Codecov Report

Merging #535 (4020d0f) into main (c6cc2e5) will increase coverage by 0.26%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #535      +/-   ##
==========================================
+ Coverage   81.01%   81.27%   +0.26%     
==========================================
  Files          19       19              
  Lines        3597     3631      +34     
  Branches      991     1008      +17     
==========================================
+ Hits         2914     2951      +37     
+ Misses        451      449       -2     
+ Partials      232      231       -1     
Impacted Files Coverage Δ
schema_salad/avro/schema.py 67.24% <100.00%> (+4.50%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c6cc2e5...4020d0f. Read the comment docs.

@tetron
Copy link
Member

tetron commented May 6, 2022

If I understand correctly, the goal is to be able to re-specify the type of a record field with a narrower range of allowed types than the the field in record it inherits from.

This seems reasonable, since the inherited type will still be a valid shape of the parent type.

Implementation comments:

  • Should recognize parent field type of "Any" (with reminder that "Any" is any non null)
  • Should say something about this in the documentation https://www.commonwl.org/v1.2/SchemaSalad.html#Inheritance_and_specialization -- is this a schema salad 1.2 feature?
  • Implementation covers arrays, but not records and enums. Is that a stretch goal or intentionally excluded? If we support narrowing for those types, should it be based on explicit inheritance, or duck typing (I would say duck typing, but I wanted to raise the issue).

@tetron
Copy link
Member

tetron commented May 6, 2022

I'm also curious, what is the specific motivation is to add this now?

Copy link
Member

@tetron tetron left a comment

Choose a reason for hiding this comment

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

See previous comments

@mr-c
Copy link
Member Author

mr-c commented May 6, 2022

I'm also curious, what is the specific motivation is to add this now?

It would help with common-workflow-language/cwltool#1665

@mr-c
Copy link
Member Author

mr-c commented May 6, 2022

explicit inheritance, or duck typing

is_subtype() is only triggered if the existing field has inherited_from set; so it is always an explicit inheritance check, in a way. However I'm currently comparing enums & records via duck typing.

@mr-c
Copy link
Member Author

mr-c commented May 6, 2022

  • is this a schema salad 1.2 feature?

Good point, I've added documentation about that.

@mr-c mr-c merged commit b725d43 into main May 18, 2022
@mr-c mr-c deleted the type_narrowing branch May 18, 2022 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants