Skip to content

fix Rngs.__getattr__ returning default stream for dunder names (#5375) - #5379

Merged
copybara-service[bot] merged 1 commit into
google:mainfrom
mohsinm-dev:fix-rngs-dunder-getattr
Apr 13, 2026
Merged

copybara-service[bot] merged 1 commit into
google:mainfrom
mohsinm-dev:fix-rngs-dunder-getattr

Conversation

@mohsinm-dev

Copy link
Copy Markdown
Contributor

Fixes #5375

Rngs.__getattr__ falls back to returning the default RngStream for any attribute name not explicitly
defined, including dunder names like __pydantic_serializer__. This breaks any library that probes for
protocol support via hasattr/getattr on dunder names.

Added an early guard in __getattr__ to raise AttributeError for dunder names so only user-chosen
stream names trigger the fallback.

if name.startswith('__') and name.endswith('__'):
    raise AttributeError(name)

@samanklesaria
samanklesaria force-pushed the fix-rngs-dunder-getattr branch from c7b5bf0 to fef7722 Compare March 31, 2026 17:30
@samanklesaria
samanklesaria force-pushed the fix-rngs-dunder-getattr branch from fef7722 to 4f6b33f Compare April 7, 2026 21:26
@copybara-service
copybara-service Bot merged commit 228c50e into google:main Apr 13, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nnx.Rngs.__*__ returns the default stream, which causes confusing breakage in combination with other packages

3 participants