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

Be more consistent with Python variable prefixes #1908

Merged
merged 1 commit into from
May 29, 2024

Conversation

bendk
Copy link
Contributor

@bendk bendk commented Dec 20, 2023

Always use uniffi, Uniffi, or UNIFFI for module-level names. Add a leading underscore for private class members. I think this is the most Pythonic naming style. Because we define __all__ for modules, there's no chance that users will accidentally import the UniFFI items with from module import *

Before there were lots of leading underscores, but I don't see the point and it doesn't feel Pythonic to me.

I think the general contract with our users should be that we own the uniffi prefix. If they want to name something UniffiFoo, then they take the risk of a name collision.

This is my personal take on the matter, but I'm fine with any naming scheme. I just think we should be consistent about it.

@bendk bendk requested review from badboy and jeddai December 20, 2023 00:51
@bendk bendk requested a review from a team as a code owner December 20, 2023 00:51
Comment on lines 354 to 355
Some(suffix) => format!("UniffiRustBuffer{suffix}"),
None => "UniffiRustBuffer".to_string(),
Copy link
Member

Choose a reason for hiding this comment

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

The underscores were actually added in #1599

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doh!

I just updated the PR to always use the underscores. PEP 8 seems to say we don't need them if we use __all__, but the autocomplete example from 1599 is pretty convincing to me.

I also updated the names for a few more functions. _rust_call is now _uniffi_rust_call

@bendk
Copy link
Contributor Author

bendk commented Dec 20, 2023

I also added a README for the templates that goes over naming.

Always use `_uniffi`, `_Uniffi`, or `_UNIFFI` for module-level names.
The leading underscore is to indicate private variables and makes it so
the names don't appear in autocomplete. I think this is the most
Pythonic naming style.

Use `_uniffi` rather than simply `_` to avoid name collisions. I think
the general contract with our users should be that we own the `uniffi`
prefix.  If they want to name something `UniffiFoo`, then they take the
risk of a name collision.
@bendk bendk force-pushed the python-variable-prefixes branch from a5647f4 to 59c17be Compare May 24, 2024 16:10
@bendk
Copy link
Contributor Author

bendk commented May 24, 2024

I've been trying to clean up my old branches and finally got around to this one. There's not that much left in this PR, but I think would still be good to merge. WDYT?

Copy link
Member

@mhammond mhammond left a comment

Choose a reason for hiding this comment

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

This seems like an improvement to me!

@bendk bendk merged commit 396e451 into mozilla:main May 29, 2024
5 checks passed
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.

None yet

3 participants