Skip to content

Add Psych.safe_dump and the missing load and dump keywords - #3275

Merged
ksss merged 1 commit into
ruby:masterfrom
APX403:psych-safe-dump-keywords
Nov 9, 2026
Merged

ksss merged 1 commit into
ruby:masterfrom
APX403:psych-safe-dump-keywords

Conversation

@APX403

@APX403 APX403 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Closes #2518

Psych.safe_dump has no signature, so type checkers that read these signatures do not know about it (castwide/solargraph#959):

$ rbs -r psych method --singleton Psych safe_dump
Cannot find method: safe_dump

Psych.load and Psych.load_file also lack the keywords load has taken since psych 4 made it safe by default: permitted_classes:, permitted_symbols: and aliases:. A YAML file with aliases or dates needs them, as in YAML.load_file("config/database.yml", aliases: true).

This adds:

  • Psych.safe_dump, with the overloads of Psych.dump plus permitted_classes:, permitted_symbols: and aliases:
  • permitted_classes:, permitted_symbols:, aliases: and strict_integer: to Psych.load and Psych.load_file
  • strict_integer: to Psych.safe_load, Psych.safe_load_file and Psych.unsafe_load_file, which Psych.unsafe_load already declares
  • stringify_names: to Psych.dump and Psych.safe_dump

The safe_dump comment is generated by rake annotate. parse_symbols: (psych 5.3) is left out because the stdlib tests run with psych 4.0.6, which goodcheck pins in Gemfile.lock and which does not have it.

@ksss ksss left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@ksss
ksss added this pull request to the merge queue Nov 9, 2026
Merged via the queue into ruby:master with commit e93005e Nov 9, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

safe_dump function missing from Psych

2 participants