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

[python] FR: Drop table names prefixing generated methods #6309

Closed
rhofour opened this issue Dec 6, 2020 · 12 comments
Closed

[python] FR: Drop table names prefixing generated methods #6309

rhofour opened this issue Dec 6, 2020 · 12 comments

Comments

@rhofour
Copy link
Contributor

rhofour commented Dec 6, 2020

Right now the generated Python methods feel excessively verbose. All of the methods for building a table are prefixed with the table's name (ex: MyGame.Sample.Weapon.WeaponStart(builder)).

I see how this is necessary if these were intended to be imported directly (from MyGame.Sample.Weapon import *), but this is considered poor practice and isn't what the tutorial shows. If these methods simply dropped the prefix then MyGame.Sample.Weapon.WeaponStart would become the shorter, but completely unambiguous MyGame.Sample.Weapon.Start.

Would there be any interest in a PR doing this? Shorter variants could be added that simply point to the existing methods to avoid breaking backwards compatibility (though this would still lead to conflicts for people who use import *).

Another minor advantage is this would allow Python code that could do things like generically start any table. I don't have use for this, but maybe someone else will.

@aardappel
Copy link
Collaborator

Hmm, not a Python user so hard to say how common this import * method is going to be. We may need yet another flag?

Opinions @rw @lu-wang-g ?

@rw
Copy link
Contributor

rw commented Dec 7, 2020

@rhofour This sounds like a good idea. I particularly like your suggestion that this could make it easier for users to operate on generated code. This seems part of a bigger goal of ours: make the generated Python code more idiomatic.

@lu-wang-g
Copy link
Contributor

Yeah, I agree this will make the generated code a lot concise, and it's also aligned with Google's Python Code Style recommendation.

I main concern is the API incompatibility issue. As @aardappel said, we could start with a flag, and then fully upgrade to the "simpler version" in the next major version release, such as Flatbuffers v12.

@rhofour
Copy link
Contributor Author

rhofour commented Dec 8, 2020

Sounds good, I'll start work on a PR.

@rhofour
Copy link
Contributor Author

rhofour commented Dec 12, 2020

I've seen several mentions of a new release coming soon, should I still stick with a flag or can I just make this a breaking change?

@aardappel
Copy link
Collaborator

@rw do you feel this is worth a breaking change?

@rhofour
Copy link
Contributor Author

rhofour commented Dec 14, 2020

I can modify my PR to make it slightly less breaking by making all the old names point to the new ones. I think it would still break for people who use "import *", but that's smaller than the current change.

That said, I (obviously) personally feel like these new names are much more idiomatic and are worth the change. Making the changes in the tutorial was actually not too bad. It's a lot of lines changed, but with a few regexps it's pretty easy.

@rw
Copy link
Contributor

rw commented Dec 15, 2020

I'd like this to not break anyone's code for now; e.g. TFLite relies on the current naming: #6336 (comment)

@rhofour
Copy link
Contributor Author

rhofour commented Dec 22, 2020

I think this should be included in the 2.0 tracking: #6353
As written it shouldn't break most people, but it will break anyone using 'import *' and I believe that's unavoidable without hiding it behind a flag.

@aardappel
Copy link
Collaborator

So, are we making any non-breaking changes related to this before 2.0, or can we close this / leave it till after 2.0?

@rhofour
Copy link
Contributor Author

rhofour commented Jan 25, 2021

The PR I have out should be minimally breaking. All the old method names are there with a deprecated comment so only people using import * will get broken.

I can check if it needs to be updated to safely merge later tonight.

@aardappel
Copy link
Collaborator

Closing, since the related PR was merged.

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

No branches or pull requests

4 participants