ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:95008] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given
       [not found] <redmine.issue-16173.20190920193245@ruby-lang.org>
@ 2019-09-20 19:32 ` burdettelamar
  2019-09-20 23:10 ` [ruby-core:95009] " XrXr
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: burdettelamar @ 2019-09-20 19:32 UTC (permalink / raw)
  To: ruby-core

Issue #16173 has been reported by burdettelamar@yahoo.com (Burdette Lamar).

----------------------------------------
Bug #16173: ENV.delete returns nil when name does not exist and block given
https://bugs.ruby-lang.org/issues/16173

* Author: burdettelamar@yahoo.com (Burdette Lamar)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Attached diff.txt:

* ENV.delete for nonexistent name and block given:
  * Test enhanced to verify return value is nil.
  * Documentation corrected to say that return value is nil, not value.


---Files--------------------------------
diff.txt (961 Bytes)


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:95009] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given
       [not found] <redmine.issue-16173.20190920193245@ruby-lang.org>
  2019-09-20 19:32 ` [ruby-core:95008] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given burdettelamar
@ 2019-09-20 23:10 ` XrXr
  2019-09-21  7:09 ` [ruby-core:95012] " nobu
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: XrXr @ 2019-09-20 23:10 UTC (permalink / raw)
  To: ruby-core

Issue #16173 has been updated by alanwu (Alan Wu).


This gives the impression that the return value is always nil, which isn't true when the environment variable exists.
Maybe it's worth clarifying that.

----------------------------------------
Bug #16173: ENV.delete returns nil when name does not exist and block given
https://bugs.ruby-lang.org/issues/16173#change-81637

* Author: burdettelamar@yahoo.com (Burdette Lamar)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Attached diff.txt:

* ENV.delete for nonexistent name and block given:
  * Test enhanced to verify return value is nil.
  * Documentation corrected to say that return value is nil, not value.


---Files--------------------------------
diff.txt (961 Bytes)


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:95012] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given
       [not found] <redmine.issue-16173.20190920193245@ruby-lang.org>
  2019-09-20 19:32 ` [ruby-core:95008] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given burdettelamar
  2019-09-20 23:10 ` [ruby-core:95009] " XrXr
@ 2019-09-21  7:09 ` nobu
  2019-09-21 15:55 ` [ruby-core:95017] " burdettelamar
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: nobu @ 2019-09-21  7:09 UTC (permalink / raw)
  To: ruby-core

Issue #16173 has been updated by nobu (Nobuyoshi Nakada).


Comparing with `Hash#delete`, it looks that the document is correct and the code is wrong.

```diff
diff --git i/hash.c w/hash.c
index 8b84a14484..7880178dc8 100644
--- i/hash.c
+++ w/hash.c
@@ -4779,7 +4779,7 @@ env_delete_m(VALUE obj, VALUE name)
     VALUE val;
 
     val = env_delete(name);
-    if (NIL_P(val) && rb_block_given_p()) rb_yield(name);
+    if (NIL_P(val) && rb_block_given_p()) val = rb_yield(name);
     return val;
 }
 
diff --git i/test/ruby/test_env.rb w/test/ruby/test_env.rb
index b01c3b12ee..1a7656ea7d 100644
--- i/test/ruby/test_env.rb
+++ w/test/ruby/test_env.rb
@@ -107,6 +107,7 @@
     assert_invalid_env {|v| ENV.delete(v)}
     assert_nil(ENV.delete("TEST"))
     assert_nothing_raised { ENV.delete(PATH_ENV) }
+    assert_equal("NO TEST", ENV.delete("TEST") {|name| "NO "+name})
   end
 
   def test_getenv
```


----------------------------------------
Bug #16173: ENV.delete returns nil when name does not exist and block given
https://bugs.ruby-lang.org/issues/16173#change-81639

* Author: burdettelamar@yahoo.com (Burdette Lamar)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Attached diff.txt:

* ENV.delete for nonexistent name and block given:
  * Test enhanced to verify return value is nil.
  * Documentation corrected to say that return value is nil, not value.


---Files--------------------------------
diff.txt (961 Bytes)


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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [ruby-core:95017] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given
       [not found] <redmine.issue-16173.20190920193245@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-09-21  7:09 ` [ruby-core:95012] " nobu
@ 2019-09-21 15:55 ` burdettelamar
  2019-09-21 17:11 ` [ruby-core:95019] " burdettelamar
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: burdettelamar @ 2019-09-21 15:55 UTC (permalink / raw)
  To: ruby-core

Issue #16173 has been updated by burdettelamar@yahoo.com (Burdette Lamar).


Thanks, @nobu, but I'm not going to propose a change to the functionality.

----------------------------------------
Bug #16173: ENV.delete returns nil when name does not exist and block given
https://bugs.ruby-lang.org/issues/16173#change-81644

* Author: burdettelamar@yahoo.com (Burdette Lamar)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Attached diff.txt:

* ENV.delete for nonexistent name and block given:
  * Test enhanced to verify return value is nil.
  * Documentation corrected to say that return value is nil, not value.


---Files--------------------------------
diff.txt (961 Bytes)


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:95019] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given
       [not found] <redmine.issue-16173.20190920193245@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-09-21 15:55 ` [ruby-core:95017] " burdettelamar
@ 2019-09-21 17:11 ` burdettelamar
  2019-09-22 18:40 ` [ruby-core:95038] " eregontp
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: burdettelamar @ 2019-09-21 17:11 UTC (permalink / raw)
  To: ruby-core

Issue #16173 has been updated by burdettelamar@yahoo.com (Burdette Lamar).

File diff.txt added

Thanks, @alanwu.  I'm refreshing diff.txt with more fulsome documentation, along with enhanced testing.

----------------------------------------
Bug #16173: ENV.delete returns nil when name does not exist and block given
https://bugs.ruby-lang.org/issues/16173#change-81646

* Author: burdettelamar@yahoo.com (Burdette Lamar)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Attached diff.txt:

* ENV.delete for nonexistent name and block given:
  * Test enhanced to verify return value is nil.
  * Documentation corrected to say that return value is nil, not value.


---Files--------------------------------
diff.txt (961 Bytes)
diff.txt (2.22 KB)


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:95038] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given
       [not found] <redmine.issue-16173.20190920193245@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2019-09-21 17:11 ` [ruby-core:95019] " burdettelamar
@ 2019-09-22 18:40 ` eregontp
  2019-09-24 18:31 ` [ruby-core:95063] " burdettelamar
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: eregontp @ 2019-09-22 18:40 UTC (permalink / raw)
  To: ruby-core

Issue #16173 has been updated by Eregon (Benoit Daloze).


IMHO it's better to fix behavior to be consistent with Hash#delete.
And the compatibility risk seems non existent here.

So I think we should change behavior, and not change documentation which would be inconsistent with Hash#delete.
+1 for @nobu's patch.

----------------------------------------
Bug #16173: ENV.delete returns nil when name does not exist and block given
https://bugs.ruby-lang.org/issues/16173#change-81669

* Author: burdettelamar@yahoo.com (Burdette Lamar)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Attached diff.txt:

* ENV.delete for nonexistent name and block given:
  * Test enhanced to verify return value is nil.
  * Documentation corrected to say that return value is nil, not value.


---Files--------------------------------
diff.txt (2.22 KB)


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:95063] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given
       [not found] <redmine.issue-16173.20190920193245@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2019-09-22 18:40 ` [ruby-core:95038] " eregontp
@ 2019-09-24 18:31 ` burdettelamar
  2019-09-24 19:10 ` [ruby-core:95065] " merch-redmine
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: burdettelamar @ 2019-09-24 18:31 UTC (permalink / raw)
  To: ruby-core

Issue #16173 has been updated by burdettelamar@yahoo.com (Burdette Lamar).


I, being a member only of The Outer Party, can't merge anything here.

I'm agnostic on whether the change should be to the documentation or to the code.  My part was just to note the discrepancy.

Can someone in The Inner Party take action?

Thanks,
Burdette

----------------------------------------
Bug #16173: ENV.delete returns nil when name does not exist and block given
https://bugs.ruby-lang.org/issues/16173#change-81696

* Author: burdettelamar@yahoo.com (Burdette Lamar)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Attached diff.txt:

* ENV.delete for nonexistent name and block given:
  * Test enhanced to verify return value is nil.
  * Documentation corrected to say that return value is nil, not value.


---Files--------------------------------
diff.txt (2.22 KB)


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:95065] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given
       [not found] <redmine.issue-16173.20190920193245@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2019-09-24 18:31 ` [ruby-core:95063] " burdettelamar
@ 2019-09-24 19:10 ` merch-redmine
  2019-10-01  3:34 ` [ruby-core:95166] " nobu
  2019-10-01 10:27 ` [ruby-core:95170] " nobu
  9 siblings, 0 replies; 10+ messages in thread
From: merch-redmine @ 2019-09-24 19:10 UTC (permalink / raw)
  To: ruby-core

Issue #16173 has been updated by jeremyevans0 (Jeremy Evans).


I also agree that nobu's patch should be merged.

----------------------------------------
Bug #16173: ENV.delete returns nil when name does not exist and block given
https://bugs.ruby-lang.org/issues/16173#change-81698

* Author: burdettelamar@yahoo.com (Burdette Lamar)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Attached diff.txt:

* ENV.delete for nonexistent name and block given:
  * Test enhanced to verify return value is nil.
  * Documentation corrected to say that return value is nil, not value.


---Files--------------------------------
diff.txt (2.22 KB)


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:95166] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given
       [not found] <redmine.issue-16173.20190920193245@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2019-09-24 19:10 ` [ruby-core:95065] " merch-redmine
@ 2019-10-01  3:34 ` nobu
  2019-10-01 10:27 ` [ruby-core:95170] " nobu
  9 siblings, 0 replies; 10+ messages in thread
From: nobu @ 2019-10-01  3:34 UTC (permalink / raw)
  To: ruby-core

Issue #16173 has been updated by nobu (Nobuyoshi Nakada).


burdettelamar@yahoo.com (Burdette Lamar) wrote:
> Thanks, @alanwu.  I'm refreshing diff.txt with more fulsome documentation, along with enhanced testing.

Thank you for the patch.

```diff
+ * Deletes the environment variable for +name+ if it exists (ignoring the block, if given); returns +nil+:
+ *   ENV.delete('LINES') # => '300'
+ *   ENV.delete('COLUMNS') { |name| fail 'boo' } # => '120'
```

It should return the old value, not `nil`.

```diff
+ * Calls the block and returns +nil+ if the environment variable does not exist and block given:
+ *   ENV.delete('NOSUCH') { |name| } # => nil
```

Non-empty block and non-nil result feels better to me.

----------------------------------------
Bug #16173: ENV.delete returns nil when name does not exist and block given
https://bugs.ruby-lang.org/issues/16173#change-81803

* Author: burdettelamar@yahoo.com (Burdette Lamar)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Attached diff.txt:

* ENV.delete for nonexistent name and block given:
  * Test enhanced to verify return value is nil.
  * Documentation corrected to say that return value is nil, not value.


---Files--------------------------------
diff.txt (2.22 KB)


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:95170] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given
       [not found] <redmine.issue-16173.20190920193245@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2019-10-01  3:34 ` [ruby-core:95166] " nobu
@ 2019-10-01 10:27 ` nobu
  9 siblings, 0 replies; 10+ messages in thread
From: nobu @ 2019-10-01 10:27 UTC (permalink / raw)
  To: ruby-core

Issue #16173 has been updated by nobu (Nobuyoshi Nakada).


https://github.com/nobu/ruby/pull/new/bug/16173-ENV.delete-block

----------------------------------------
Bug #16173: ENV.delete returns nil when name does not exist and block given
https://bugs.ruby-lang.org/issues/16173#change-81806

* Author: burdettelamar@yahoo.com (Burdette Lamar)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Attached diff.txt:

* ENV.delete for nonexistent name and block given:
  * Test enhanced to verify return value is nil.
  * Documentation corrected to say that return value is nil, not value.


---Files--------------------------------
diff.txt (2.22 KB)


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-10-01 10:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-16173.20190920193245@ruby-lang.org>
2019-09-20 19:32 ` [ruby-core:95008] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given burdettelamar
2019-09-20 23:10 ` [ruby-core:95009] " XrXr
2019-09-21  7:09 ` [ruby-core:95012] " nobu
2019-09-21 15:55 ` [ruby-core:95017] " burdettelamar
2019-09-21 17:11 ` [ruby-core:95019] " burdettelamar
2019-09-22 18:40 ` [ruby-core:95038] " eregontp
2019-09-24 18:31 ` [ruby-core:95063] " burdettelamar
2019-09-24 19:10 ` [ruby-core:95065] " merch-redmine
2019-10-01  3:34 ` [ruby-core:95166] " nobu
2019-10-01 10:27 ` [ruby-core:95170] " nobu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).