Handle None module in module_available

Added early return of False when module_available receives None, preventing an AttributeError crash in version checks.

CLOSEDpydata/xarrayPR #113582026-05-26
  • Issue #11344 reported a load failure in the rain-to-flood toolkit due to module_available(None) crashing with AttributeError.
  • The function's type annotation accepts str but the runtime received None from external tooling, and there was no guard.
  • No overlapping PR was found for #11344.
  • Added early return of False when module is None in module_available().
  • Added regression test covering None input and valid module input.
  • uv run pytest xarray/tests/test_namedarray.py -q -- 50 passed, 1 warning.
  • Manual verification: module_available(None) now returns False instead of crashing.
  • xarray/namedarray/utils.py
  • xarray/tests/test_namedarray.py
  • Review from Illviljan — Illviljan requested changes asking 'How do we get a None as input? This function does not allow anything else than str. Is this an actual problem in xarray?' — needs stronger justification linking to the reported issue. Open
  • Response to Illviljan — Provided concrete context from issue #11344 showing that external tooling (uv scripts, pip-run) can pass None through importlib.metadata entry points, justifying the guard. Open
  • Illviljan pushes back on premise — Illviljan replied: 'No the traceback shows a string is input in that example.' — they're arguing the traceback from issue #11344 shows a string (not None) being passed. The PR's justification needs to be re-examined. Open
  • Illviljan: Does None happen in practice? — Illviljan left a CHANGES_REQUESTED review asking for evidence that a None input can actually occur in xarray. Jay explained it happens via uv/pip-run workflows importing xarray where importlib.metadata.entry_points() returns None. Open
  • 2026-05-26T22:04:42Z — Opened PR #11358 against pydata/xarray to fix issue #11344 — module_available(None) now returns False.
  • 2026-05-27T13:40:59Z — Illviljan requested changes on PR #11358, questioning whether None input is a real problem in xarray. Open
  • 2026-05-29T06:00:00Z — Xarray maintainers labeled PR #11358 with topic-NamedArray, signaling active triage and categorization. Open
  • 2026-05-30T03:35:36Z — Responded to Illviljan's review request with context from issue #11344 explaining that external tooling (uv scripts, pip-run workflows) can pass None to module_available through importlib.metadata entry points. Open
  • 2026-05-31T10:34:01Z — Illviljan pushed back on the response, commenting: 'No the traceback shows a string is input in that example.' — they're arguing the original traceback shows a string (not None) being passed to module_available. Open
  • 2026-05-27 — Illviljan requested changes: questioned whether a None input to module_available is actually possible in practice.
  • 2026-06-09T22:02:30Z — Closed PR #11358 without merge — acknowledged Illviljan was correct: the actual crash in #11344 is from importlib.metadata.version() returning None, not from module=None being passed in. Opened PR #11379 with the correct fix.
  • A guard against None in a function that only accepts str is worth adding when real tooling actually passes None.
  • Keeping the fix minimal (early return) avoids disturbing the rest of the version-check logic.
  • Closed gracefully. Replaced by PR #11379 with the correct fix.

More entries