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

Record type with optional keys #504

Open
HoneyryderChuck opened this issue Dec 5, 2020 · 3 comments
Open

Record type with optional keys #504

HoneyryderChuck opened this issue Dec 5, 2020 · 3 comments
Milestone

Comments

@HoneyryderChuck
Copy link
Contributor

The record type definition forces all keys to be passed, whereas in most cases, one already handles the case to a default when one of the record values isn't passed. Picking up the linked example:

{ id: Integer, name: String }     # Hash object like `{ id: 31, name: "John" }`
# However, I want to handle
# Hash object like `{ name: "John" }` where id is attributed inside the function
# this isn't handled because I can't define
# { ?id: Integer, name: String } 
# like for kwargs

The only way to support this right now is to repeat all combinations in a type definition, which is a bit brittle.

WDYT?

@soutaro
Copy link
Member

soutaro commented Dec 7, 2020

In fact, the existence of the key is not checked in the runtime type checker and Steep also allows omitting optional record keys. (soutaro/steep#256)

So, my intuition is that supporting optional keys is better, but we can postpone working for it after Ruby 3.0.

@soutaro soutaro added this to the After Ruby 3.0 milestone Dec 7, 2020
@HoneyryderChuck
Copy link
Contributor Author

@soutaro do you think it's time for devising a plan for this? Caught this again while using steep and stdlib's URI::Generic.build signature, which is currently incorrect, as it expects all options to be passed, whereas they're all optional.

@ShalokShalom
Copy link

I would be also interested in this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants