random.randint() no longer accepts float arguments in Python 3.13

XMLWordPrintableJSON

    • Type: Sub-task
    • Resolution: Fixed
    • Priority: Major - P3
    • 8.3.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • DevProd Correctness
    • Fully Compatible
    • Correctness 2026-01-26, Correctness 2026-02-09
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Error:

      File "/opt/mongodbtoolchain/v5/lib/python3.13/random.py", line 340, in randint
        return self.randrange(a, b+1)
               ~~~~~~~~~~~~~~^^^^^^^^
      File "/opt/mongodbtoolchain/v5/lib/python3.13/random.py", line 316, in randrange
        istop = _index(stop)
      TypeError: 'float' object cannot be interpreted as an integer
      

      Description:

      Python 3.13 removed support for passing float arguments to random.randint(), which was deprecated in Python 3.10.

      The Problem in Our Code:

      In config_fuzzer_limits.py, we have:

      "replBatchLimitOperations": {
          "min": 1,
          "max": 0.2 * 1000 * 1000,  # Evaluates to float 200000.0, not int 200000
          ...
      }
      

      The arithmetic 0.2 * 1000 * 1000 produces a float type (200000.0) because one operand is a float. When this is passed to randint(), Python 3.13 rejects it.

      Why It Worked in Python 3.10/3.11:

      Python 3.10 and 3.11's randrange() implementation:

      try:
          istart = _index(start)  # Strict integer check
      except TypeError:
          istart = int(start)     # Fallback: convert float to int
          if istart != start:
              raise ValueError("non-integer arg")
          # Warn but continue (DeprecationWarning was hidden by default)
      

      These versions would convert floats to integers and issue a DeprecationWarning (which was hidden by default, so developers didn't see it).

      Why It Fails in Python 3.13:

      Python 3.13's randrange() removed the fallback conversion:

      istart = _index(start)  # Strict check only - raises TypeError for floats
      

      The _index() function (operator.index()) only accepts true integer types and raises TypeError for floats, even floats with no fractional part like 200000.0.

      References:

            Assignee:
            Nicholas Jefferies
            Reporter:
            Nicholas Jefferies
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: