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

Remove self restriction from Object.from_{json,yaml} #8489

Merged
merged 1 commit into from
Nov 23, 2019

Conversation

straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented Nov 18, 2019

Object.new is not restricted to self, so .from_json and .from_yaml should neither.

The generic Object.new is typically supposed to return a new instance of the respective type. That's the default behaviour. But the method can be overridden by implementing classes.

The overloads .new(JSON::PullParser) and .new(YAML::ParseContext, YAML::Nodes::Node) are not required to return an instance of the type either. There may be valid use cases where the return value is actually a different type.

/cc #8473 for context

Object.new is not restricted to self, so .from_json and .from_yaml should
neither.
Copy link
Member

@asterite asterite left a comment

Choose a reason for hiding this comment

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

Thank you!

Copy link
Member

@RX14 RX14 left a comment

Choose a reason for hiding this comment

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

Sure, why not.

@RX14 RX14 added this to the 0.32.0 milestone Nov 23, 2019
@RX14 RX14 merged commit 5444a06 into crystal-lang:master Nov 23, 2019
@straight-shoota straight-shoota deleted the fix/object-from-json-self branch November 23, 2019 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants