Support class Foo < Data.define(:a, :b) as a documented superclass - #1705
Open
svyatov wants to merge 1 commit into
Open
Support class Foo < Data.define(:a, :b) as a documented superclass#1705svyatov wants to merge 1 commit into
svyatov wants to merge 1 commit into
Conversation
ClassHandler has no branch for Data.define, so the class registers with no superclass, logs an "Undocumentable superclass" warning, and renders as inheriting Object. The constant form gained support in lsegal#1600, which left the class form to a separate PR. The superclass now resolves to Data. Members become read-only attributes through the reader-only path the constant form uses, lifted into StructHandlerMethods#create_readers. The legacy parser gains superclass resolution only; member specs are gated to the Ripper parser, as lsegal#1600's are.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
class Foo < Data.define(:a, :b)currently registers with no superclass. The parser logs[warn]: in YARD::Handlers::Ruby::ClassHandler: Undocumentable superclass (class was added without superclass), and the rendered docs claim the class inheritsObject. #1533 reports this exact case. #1600 added the constant formFoo = Data.define(:a, :b)and invited this change:Here is that separate PR. The strong opinion: current tooling forces the inheritance form on some projects, whatever style one prefers.
.rband neversig/, so hover docs on members need a documented reader per member:def a = super. That reader works only in the inheritance form. In the block form,Data.define(:a) do def a = super endraisesNoMethodError: super: no superclass method 'a'at runtime, because the block runs on the same class that defines the reader.::Object(do block inside class with in Data.define not correctly identified soutaro/steep#963), and the rbs guidedocs/data_and_struct.mdrecords the same preference for inheriting.Datadocumentation not showing the form also holds forclass Foo < Struct.new(...), which YARD has long supported.Changes:
ClassHandler#parse_superclassresolvesData.define(...)toData, next to the existingStruct.newbranch. The warning is gone and the ancestry renders correctly.ConstantHandler#process_dataclassmoved toStructHandlerMethods#create_readers, and both handlers call it.Verified against a real tree: a gem that generates 361 such classes from the Telegram Bot API spec. Before: 361 warnings. After: zero warnings, every class renders
Dataancestry with read-only member attributes, and explicitly documented readers in class bodies keep their own docstrings.Completed Tasks
bundle exec rakelocally (if code is attached to PR).