
Issue #20606 has been updated by jeremyevans0 (Jeremy Evans). This change would be simple to implement, and I agree the fiber/thread variable inconsistency seems odd. There are specs for the current behavior. However, I checked and the specs appear to be added by you only a couple days ago. It seems odd to me to add specs for something you think is a bug. I think specs and tests should attempt to reflect desired behavior, not attempt to exhaustively describe current behavior. Personally, I get annoyed when I am fixing a bug and have to update specs that attempt to document current behavior without considering whether behavior is desired (this happens way more often with specs than with tests). It is better to leave behavior unspecified/untested than to add specs/tests for behavior that may not be desired. I'm not opposed to changing the behavior, but raising an exception when one was not previously raised presents backwards compatibility issues. We would probably have to warn in 3.4 and not raise until 3.5 (or later). Please add this to the developer meeting agenda if you would like the behavior to change. ---------------------------------------- Bug #20606: Thread#thread_variable_get, Thread#thread_variable? and Thread#[] methods handle non-String/Symbol parameter values differently https://bugs.ruby-lang.org/issues/20606#change-108949 * Author: andrykonchin (Andrew Konchin) * Status: Open * ruby -v: 3.2.4 * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- The `Thread#thread_variable_get`, `Thread#thread_variable?` and `Thread#[]` methods handle the `key` parameter that is not a String or a Symbol in different way but I would expect them to be consistent and raise an exception. When no thread-local variables were assigned to a thread the `Thread#thread_variable_get` and `Thread#thread_variable?` methods don't raise `TypeError` when argument is of incorrect type. But `Thread#[]` does raise `TypeError` exception: ```ruby t = Thread.new {}.join puts t.thread_variable_get(123).inspect # nil puts t.thread_variable?(123).inspect # false t[123] # `[]': 123 is not a symbol nor a string (TypeError) ``` -- https://bugs.ruby-lang.org/