From: Austin Ziegler Date: 2020-12-03T17:44:38-05:00 Subject: [ruby-core:101231] Re: [Ruby master Feature#17055] Allow suppressing uninitialized instance variable and method redefined verbose mode warnings --===============1127043503== Content-Type: multipart/alternative; boundary="000000000000cc92aa05b5971be1" --000000000000cc92aa05b5971be1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable What does this mean? > Considering that you can alias a method to itself to avoid the warning, and therefore do not need to remove the method first (which would cause a race condition), I am dropping my request to add `expected_redefined_method?(method_name)`. I have code that I=E2=80=99ve written to get around some rdoc silliness tha= t does: # rdoc documentation for foo. attr_writer :foo undef :foo=3D def foo=3D(x) #:nodoc: # specialized foo assignment code end If I didn=E2=80=99t do this, RDoc documents both the attribute and the `foo= =3D` method (or it did the last time I checked) even though all I want documented is the attribute for readability. How would I make it so that I don=E2=80=99t need to do `undef :foo=3D` here, as that has been one thing t= hat has failed this code (_hard_) with both type analyzers for Ruby. -a On Wed, Dec 2, 2020 at 4:26 PM wrote: > Issue #17055 has been updated by jeremyevans0 (Jeremy Evans). > > > During the November developer meeting, @matz seems in favor of completely > removing the undefined instance variable warning. I am strongly in favor > of removing the undefined instance variable warning completely, and much > prefer doing that instead of adding > `expected_uninitialized_instance_variable?`. If the undefined instance > variable warnings are removed, there is no reason to have > `expected_uninitialized_instance_variable?`. > > After discussions with @mame, the method redefinition warning is often > helpful when writing test code using test/unit or minitest/test. > Considering that you can alias a method to itself to avoid the warning, a= nd > therefore do not need to remove the method first (which would cause a rac= e > condition), I am dropping my request to add > `expected_redefined_method?(method_name)`. > > ---------------------------------------- > Feature #17055: Allow suppressing uninitialized instance variable and > method redefined verbose mode warnings > https://bugs.ruby-lang.org/issues/17055#change-88891 > > * Author: jeremyevans0 (Jeremy Evans) > * Status: Open > * Priority: Normal > ---------------------------------------- > These two verbose mode warnings are both fairly common and have good > reasons why you would not want to warn about them in specific cases. Not > initializing instance variables to nil can be much better for performance= , > and redefining methods without removing the method first is the only safe > approach in multi-threaded code. > > There are reasons that you may want to issue verbose warnings by default > in these cases. For uninitialized instance variables, it helps catch > typos. For method redefinition, it could alert you that a method already > exists when you didn't expect it to, such as when a file is loaded multip= le > times when it should only be loaded once. > > I propose we keep the default behavior the same, but offer the ability to > opt-out of these warnings by defining methods. For uninitialized instanc= e > variables in verbose mode, I propose we call > `expected_uninitialized_instance_variable?(iv)` on the object. If this > method doesn't exist or returns false/nil, we issue the warning. If the > method exists and returns true, we suppress the warning. Similarly, for > redefined methods, we call `expected_redefined_method?(method_name)` on t= he > class or module. If the method doesn't exist or returns false/nil, we > issue the warning. If the method exists and returns true, we suppress th= e > warning. > > This approach allows high performance code (uninitialized instance > variables) and safe code (redefining methods without removing) to work > without verbose mode warnings. > > I have implemented this support in a pull request: > https://github.com/ruby/ruby/pull/3371 > > ---Files-------------------------------- > t.rb (5.59 KB) > > > -- > https://bugs.ruby-lang.org/ > > Unsubscribe: > > --=20 Austin Ziegler =E2=80=A2 halostatue@gmail.com =E2=80=A2 austin@halostatue.c= a http://www.halostatue.ca/ =E2=80=A2 http://twitter.com/halostatue --000000000000cc92aa05b5971be1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
What does this mean?

&= gt; Considering that you can alias a method to itself to avoid the warning,= and therefore do not need to remove the method first (which would cause a = race condition), I am dropping my request to add `expected_redefined_method= ?(method_name)`.

I have code that I=E2=80=99ve written to get around some rdoc silliness = that does:

=C2=A0 # rdoc documentation for foo.
=C2=A0 attr_writer :foo
=C2=A0 undef :foo=3D
= =C2=A0 def foo=3D(x) #:nodoc:
=C2=A0 =C2=A0 # specialized foo ass= ignment code
=C2=A0 end

If I didn=E2=80= =99t do this, RDoc documents both the attribute and the `foo=3D` method (or= it did the last time I checked) even though all I want documented is the a= ttribute for readability. How would I make it so that I don=E2=80=99t need = to do `undef :foo=3D` here, as that has been one thing that has failed this= code (_hard_) with both type analyzers for Ruby.

= -a

On Wed, Dec 2, 2020 at 4:26 PM <merch-redmine@jeremyevans.net> wrote:
Issue #17055 has been updated by jeremyevans0 (Jeremy = Evans).


During the November developer meeting, @matz seems in favor of completely r= emoving the undefined instance variable warning.=C2=A0 I am strongly in fav= or of removing the undefined instance variable warning completely, and much= prefer doing that instead of adding `expected_uninitialized_instance_varia= ble?`.=C2=A0 If the undefined instance variable warnings are removed, there= is no reason to have `expected_uninitialized_instance_variable?`.

After discussions with @mame, the method redefinition warning is often help= ful when writing test code using test/unit or minitest/test.=C2=A0 Consider= ing that you can alias a method to itself to avoid the warning, and therefo= re do not need to remove the method first (which would cause a race conditi= on), I am dropping my request to add `expected_redefined_method?(method_nam= e)`.

----------------------------------------
Feature #17055: Allow suppressing uninitialized instance variable and metho= d redefined verbose mode warnings
https://bugs.ruby-lang.org/issues/17055#change-8= 8891

* Author: jeremyevans0 (Jeremy Evans)
* Status: Open
* Priority: Normal
----------------------------------------
These two verbose mode warnings are both fairly common and have good reason= s why you would not want to warn about them in specific cases.=C2=A0 Not in= itializing instance variables to nil can be much better for performance, an= d redefining methods without removing the method first is the only safe app= roach in multi-threaded code.

There are reasons that you may want to issue verbose warnings by default in= these cases.=C2=A0 For uninitialized instance variables, it helps catch ty= pos. For method redefinition, it could alert you that a method already exis= ts when you didn't expect it to, such as when a file is loaded multiple= times when it should only be loaded once.

I propose we keep the default behavior the same, but offer the ability to o= pt-out of these warnings by defining methods.=C2=A0 For uninitialized insta= nce variables in verbose mode, I propose we call `expected_uninitialized_in= stance_variable?(iv)` on the object.=C2=A0 If this method doesn't exist= or returns false/nil, we issue the warning.=C2=A0 If the method exists and= returns true, we suppress the warning.=C2=A0 Similarly, for redefined meth= ods, we call `expected_redefined_method?(method_name)` on the class or modu= le.=C2=A0 If the method doesn't exist or returns false/nil, we issue th= e warning.=C2=A0 If the method exists and returns true, we suppress the war= ning.

This approach allows high performance code (uninitialized instance variable= s) and safe code (redefining methods without removing) to work without verb= ose mode warnings.

I have implemented this support in a pull request: https://git= hub.com/ruby/ruby/pull/3371

---Files--------------------------------
t.rb (5.59 KB)


--
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=3Dunsubscribe= >
<http://lists.ruby-lang.org/cgi-bin/m= ailman/options/ruby-core>


--
--000000000000cc92aa05b5971be1-- --===============1127043503== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline Unsubscribe: --===============1127043503==--