Skip to content

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

Open
mohsinm-dev wants to merge 1 commit intogoogle:mainfrom
mohsinm-dev:fix-rngs-dunder-getattr
Open

fix Rngs.__getattr__ returning default stream for dunder names (#5375)#5379
mohsinm-dev wants to merge 1 commit intogoogle:mainfrom
mohsinm-dev:fix-rngs-dunder-getattr

Conversation

@mohsinm-dev
Copy link
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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

1 participant