From: akr@...
Date: 2020-08-31T02:04:04+00:00
Subject: [ruby-core:99782] [Ruby master Feature#17122] Add category to Warning#warn
Issue #17122 has been updated by akr (Akira Tanaka).
akr (Akira Tanaka) wrote in #note-13:
> But Ruby don't have "ignorable" argument that
> actual argument which corresponding formal argument may not be exist.
Maeda-sensei (@maeda) told me that Common Lisp has allow-other-keys which suppress keyword argument checking at function call.
http://www.lispworks.com/documentation/HyperSpec/Body/03_dada.htm
http://www.lispworks.com/documentation/HyperSpec/Body/03_daf.htm
```
% clisp
i i i i i i i ooooo o ooooooo ooooo ooooo
I I I I I I I 8 8 8 8 8 o 8 8
I \ `+' / I 8 8 8 8 8 8
\ `-+-' / 8 8 8 ooooo 8oooo
`-__|__-' 8 8 8 8 8
| 8 o 8 8 o 8 8
------+------ ooooo 8oooooo ooo8ooo ooooo 8
Welcome to GNU CLISP 2.49.92 (2018-02-18)
Copyright (c) Bruno Haible, Michael Stoll 1992-1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2000
Copyright (c) Sam Steingold, Bruno Haible 2001-2018
Type :h and hit Enter for context help.
[1]> (defun f (x &key y) (+ x y))
F
[2]> (f 1 :y 2)
3
[3]> (f 1 :y 2 :z 3 :allow-other-keys t)
3
[4]> (f 1 :y 2 :z 3)
*** - F: illegal keyword/value pair :Z, 3 in argument list.
The allowed keywords are (:Y)
The following restarts are available:
ABORT :R1 Abort main loop
Break 1 [5]>
```
----------------------------------------
Feature #17122: Add category to Warning#warn
https://bugs.ruby-lang.org/issues/17122#change-87299
* Author: eileencodes (Eileen Uchitelle)
* Status: Open
* Priority: Normal
----------------------------------------
Deprecation warnings and other warnings in Ruby have a category (:deprecated, etc) but those categories aren't exposed or accessible. In the most recent Ruby 2.7 upgrade at GitHub we monkey patched `Warning#warn` to be able to turn warnings into exceptions. However, there was no way to tell which warnings were deprecations and which were other types of warnings.
I want to expose the `category` on the `Warning` module so that I'm able to monkey patch `Warning#warn` and treat deprecation warnings differently from other warnings without using a regex the strings.
Here's an example program demonstrating what I'd like to get from Ruby by implementing this feature:
```ruby
module Warning
def self.warn(msg, category: nil)
if category == :deprecated
raise msg
else
super
end
end
end
def ivar
Object.new.instance_variable_get(:@ivar)
end
# Doesn't raise, but warns with verbose set
ivar
# Raises an error
Object.new.tainted?
```
The PR I worked on with @tenderlove is here: https://github.com/ruby/ruby/pull/3418
It moves the `Warning` module to be written in Ruby, updates `rb_warning_s_warn` to pass kwargs, and adds a `category` to `Warning#warn`.
--
https://bugs.ruby-lang.org/
Unsubscribe: