Skip to content

[python] Proper prefixing for shape-related methods#3236

Merged
johnkerl merged 4 commits intomainfrom
kerl/prefixing
Oct 25, 2024
Merged

[python] Proper prefixing for shape-related methods#3236
johnkerl merged 4 commits intomainfrom
kerl/prefixing

Conversation

@johnkerl
Copy link
Copy Markdown
Contributor

Issue and/or context: As tracked on issue #2407 / [sc-51048].

Note that the intended Python and R API changes are all agreed on and finalized as described in #2407.

Changes:

Resolve discrepancies between function names and #2407.

Notes for Reviewer:

@johnkerl johnkerl force-pushed the kerl/docstring-prune branch from 5a4a620 to 5c55e5f Compare October 24, 2024 19:10
Copy link
Copy Markdown
Collaborator

@jp-dark jp-dark left a comment

Choose a reason for hiding this comment

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

It can be a real pain to correctly maintain the error messages where you pass in the function names. I'm not too worried if there is an one-off need to do it just in this case, but if this is a pattern we will continue to need maybe we can file a story to investigate alternatives?

@johnkerl
Copy link
Copy Markdown
Contributor Author

It can be a real pain to correctly maintain the error messages where you pass in the function names. I'm not too worried if there is an one-off need to do it just in this case, but if this is a pattern we will continue to need maybe we can file a story to investigate alternatives?

@jp-dark quite the contrary! This is methodical and intentional for the very sake of maintainability.

  • Details of error-message content are computed in libtiledbsoma -- to avoid code duplication between Python and R
  • The function name must be the one the user invoked -- at the user level
  • Passing in the function name ensures that we are not hard-coding within libtiledbsoma what we thinik the user-facing function name is, but rather, letting the Python/R layers have control over the names.

@johnkerl
Copy link
Copy Markdown
Contributor Author

I very much do not want to lose the ability to flow user-level names (what they actually typed) down to exceptions thrown at lower levels.

It's a long-standing curse that a user sees a cryptic exception and can't map it to what they typed. Propagating a user-level function name is important for that, and if anything, we should do this more often, not less.

If your concern is double entry at the Python/R-level callsites, maybe we can use something like

import inspect
function_name_for_messages = inspect.currentframe().f_code.co_name

?

@jp-dark
Copy link
Copy Markdown
Collaborator

jp-dark commented Oct 25, 2024

If your concern is double entry at the Python/R-level callsites, maybe we can use something like

import inspect
function_name_for_messages = inspect.currentframe().f_code.co_name

Yes - this. I worked with a large Fortran codebase that required the developer to add the function name to the error messages and it led to a lot of incorrect error messages due to a combo of copy/paste errors and forgetting to update message string when a function name change occurred. So long as we are automatically getting the function names from Python/R, I'm all for propagating this pattern.

@johnkerl
Copy link
Copy Markdown
Contributor Author

@jp-dark awesome!!! :)

For reference, the R analog:

  function_name_for_messages <- sys.call(sys.parent(n=1)[[1]]

@johnkerl johnkerl changed the base branch from kerl/docstring-prune to main October 25, 2024 16:07
@johnkerl johnkerl merged commit a4f4a1b into main Oct 25, 2024
@johnkerl johnkerl deleted the kerl/prefixing branch October 25, 2024 16:08
johnkerl added a commit that referenced this pull request Oct 25, 2024
johnkerl added a commit that referenced this pull request Oct 25, 2024
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.

2 participants