Proposal: allow to specify Union type for the module-self

Offen
#2,065 1 Kommentar 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
30/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
ruby
Bereich
tooling

Rechercherichtung

Beginnen Sie mit dem bestehenden _Commentable-Interface-Workaround und der in diesem Issue vorgeschlagenen module-self-Union-Syntax. Überprüfen Sie, wie RBS module-self- und Union-Typen darstellt, und bewerten Sie anschließend die hier angesprochenen Auswirkungen auf die Typprüfung und die Laufzeitperformance. Abgeschlossen ist die Aufgabe mit einem akzeptierten Design samt Implementierung und Tests, falls der Vorschlag genehmigt wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

It would be very helpful to use Union type for the module-self.

In my project, I have a Commentable concern module used across multiple ActiveRecord models. This Commentable module uses methods commonly defined in the modules where it is included. For example, it references methods like #comments and attributes such as #user_id.

Currently, in RBS, only classes or interfaces can be specified for module-self. As a workaround, I have defined an interface as follows:

interface _Commentable
  def comments: () -> Comment::ActiveRecord_Relation
  def user_id: () -> Integer
  ...
end

module Commentable : _Commentable
end

This interface allows for proper type checking, but as the number of methods grows, the interface definition becomes more cumbersome.

If it were possible to specify a Union type for module-self, it would allow for type definitions of modules without the need to define an interface.

module Commentable : (Article | Comment | ...)
end

However, generating an interface dynamically through Union types might negatively impact runtime performance. Do you think this idea is practical?

Vorherrschende Sprache
Ruby
Sterne
2.2k
Forks
263
Ø Merge
1 T. 20 Std.
Gemergte PRs (30 T.)
64

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus ruby/rbs

Alle Issues in ruby/rbs

Ähnliche Issues

Weitere Issues zu Ruby

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.