Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add @ as py attr accessor #1431

Closed
wants to merge 4 commits into from
Closed

add @ as py attr accessor #1431

wants to merge 4 commits into from

Conversation

t-kalinowski
Copy link
Member

@t-kalinowski t-kalinowski commented Aug 3, 2023

Closes #1429
Closes #251

This enables unambiguously accessing attrs in contexts where $ mingles python attrs and items (e.g., with python dictionaries, pyspark tables). This also enables autocompletion in R outside the terminal. However, autocompletion in the IDE won't work until rstudio/rstudio#13451 is resolved.

@dfalbel
Copy link
Member

dfalbel commented Aug 15, 2023

Maybe we can add docs in this PR explaining the differences between $, [, [[ and @ so we can also fix #263.

@t-kalinowski
Copy link
Member Author

t-kalinowski commented Aug 24, 2023

I don't think merging this at this time is a good idea.

@ is valuable new syntax, which doesn't come around very often. Using it for python attribute access today doesn't strike me as a good return on value--it wouldn't add any new capability over what $ does already in practice. I don't have any better ideas for how to use @ in reticulate at this moment, but I'd rather reserve the syntax for a better idea, when it does come along.

Inside a package that uses reticulate, (e.g., pysparklyr), I think it's reasonable for package authors to opt-in to a "safer" attribute access method that doesn't fallback to __getitem__ by defining an internal S3 method, e.g.,

`@.python.builtin.object` <- function(x, name) py_to_r(py_get_attr(x, 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
2 participants