Skip to content

[rfile][python] add support for __getitem__ and __contains__ - #23965

Open
silverweed wants to merge 2 commits into
root-project:masterfrom
silverweed:rfile_getdict
Open

silverweed wants to merge 2 commits into
root-project:masterfrom
silverweed:rfile_getdict

Conversation

@silverweed

@silverweed silverweed commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

This Pull request:

adds support for the dictionary syntax in RFile:

hist = rfile['hist'] # (almost) equivalent to rfile.Get('hist')

as well as the in operator:

if 'hist' in rfile: 
  # ...

NOTE: to mirror python's default behavior with the dictionary syntax, file['obj'] will raise a KeyError if obj is not in file. This is different from file.Get('obj'), which will instead return None.

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

@dpiparo dpiparo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this useful pythonisations!

@vepadulano vepadulano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you this is really useful!

This branch has not been deployed

No deployments
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.

4 participants