ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "mame (Yusuke Endoh) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "mame (Yusuke Endoh)" <noreply@ruby-lang.org>
Subject: [ruby-core:120571] [Ruby master Bug#20980] Range#size new TypeError vs semi-open ranges
Date: Thu, 09 Jan 2025 11:42:00 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-111395.20250109114200.710@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-20980.20241224153853.710@ruby-lang.org>

Issue #20980 has been updated by mame (Yusuke Endoh).

Status changed from Open to Closed

The current behavior is intended. In principle, `#size` should return how many times `#each` will call a given block. (It could return nil as unknown.) Since beginless range does not respond to `#each`, it is now natural for `#size` to raise an exception. @naruse said he will try improving the document.

----------------------------------------
Bug #20980: Range#size new TypeError vs semi-open ranges
https://bugs.ruby-lang.org/issues/20980#change-111395

* Author: zverok (Victor Shepelev)
* Status: Closed
* ruby -v: ruby 3.4.0dev (2024-12-24T14:40:12Z master 07e89bde46) +PRISM [x86_64-linux]
* Backport: 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED
----------------------------------------
Since #18984, `Range#size` throws `TypeError` if the `begin` is not iterable (doesn't respond to `#succ`). It produces one small inconvenience compared to 3.3:

```ruby
('a'..).size #=> nil
(..'a').size 
# 3.3: nil
# 3.4: can't iterate from NilClass (TypeError) -- well, probably makes sense

# BUT:
(3..).size #=> Infinity -- cool!
(..3).size 
# 3.3: Infinity -- reasonable?
# 3.4: can't iterate from NilClass (TypeError) -- worse?
```

I believe that while 3.4's behavior is explainable, 3.3's one has better DX.

(Obviously too late to change before the release, but maybe might be considered for some patch version or Ruby 3.5?..)



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/

      reply	other threads:[~2025-01-09 11:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-24 15:39 [ruby-core:120397] " zverok (Victor Shepelev) via ruby-core
2025-01-09 11:42 ` mame (Yusuke Endoh) via ruby-core [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-111395.20250109114200.710@ruby-lang.org \
    --to=ruby-core@ml.ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).