Skip to content

Translate T.cast and T.must into RBS comments #714

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Morriar
Copy link
Collaborator

@Morriar Morriar commented Mar 18, 2025

This will now allow to translate T.must into RBS comments so this:

x = T.cast(ARGV.first, String)

becomes this:

x = ARGV.first #: as String

And T.must so this:

x = T.must(ARGV.first)

becomes this:

x = ARGV.first #: as !nil

@Morriar Morriar added the feature New feature label Mar 18, 2025
@Morriar Morriar self-assigned this Mar 18, 2025
@Morriar Morriar requested a review from a team as a code owner March 18, 2025 16:38
@Morriar Morriar force-pushed the at-rbs-annotations-must branch from 5e801ba to 23a9d85 Compare March 18, 2025 16:46
Copy link
Member

@paracycle paracycle left a comment

Choose a reason for hiding this comment

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

What happens to constructs like:

foo = T.cast(T.must(T.must(bar).baz).quux, String)

If we are not handling them then it might be good to make that explicit in the option messages and with tests.

@@ -11,6 +11,9 @@ class Assertions < Thor
desc "translate", "Translate type assertions from/to RBI and RBS"
option :from, type: :string, aliases: :f, desc: "From format", enum: ["rbi"], default: "rbi"
option :to, type: :string, aliases: :t, desc: "To format", enum: ["rbs"], default: "rbs"
option :let, type: :boolean, desc: "Translate `T.let` to `nil #: String?`", default: true
Copy link
Member

Choose a reason for hiding this comment

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

The inclusion of nil here looks out of place to me:

Suggested change
option :let, type: :boolean, desc: "Translate `T.let` to `nil #: String?`", default: true
option :let, type: :boolean, desc: "Translate `T.let` to `#: String`", default: true

I think a better message would be:

Suggested change
option :let, type: :boolean, desc: "Translate `T.let` to `nil #: String?`", default: true
option :let, type: :boolean, desc: "Translate `T.let(x, String)` to `x #: String?`", default: true

Comment on lines +15 to +16
option :cast, type: :boolean, desc: "Translate `T.cast` to `# as String`", default: true
option :must, type: :boolean, desc: "Translate `T.must` to `# as not nil`", default: true
Copy link
Member

Choose a reason for hiding this comment

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

If my suggestion above is accepted, then better messages would be:

Suggested change
option :cast, type: :boolean, desc: "Translate `T.cast` to `# as String`", default: true
option :must, type: :boolean, desc: "Translate `T.must` to `# as not nil`", default: true
option :cast, type: :boolean, desc: "Translate `T.cast(x, String)` to `x # as String`", default: true
option :must, type: :boolean, desc: "Translate `T.must(x)` to `x # as !nil`", default: true

Comment on lines +15 to +16
option :cast, type: :boolean, desc: "Translate `T.cast` to `# as String`", default: true
option :must, type: :boolean, desc: "Translate `T.must` to `# as not nil`", default: true
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
option :cast, type: :boolean, desc: "Translate `T.cast` to `# as String`", default: true
option :must, type: :boolean, desc: "Translate `T.must` to `# as not nil`", default: true
option :cast, type: :boolean, desc: "Translate `T.cast` to `# as String`", default: true
option :must, type: :boolean, desc: "Translate `T.must` to `# as !nil`", default: true

@annotation_methods << :let if let
@annotation_methods << :cast if cast
@annotation_methods << :must if must

Copy link
Member

Choose a reason for hiding this comment

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

It might be a good idea to do:

Suggested change
@annotation_methods.freeze

here.

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

Successfully merging this pull request may close these issues.

2 participants