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

Allow filenames in _CalledFromGeneratedFile to contain "/pb2/" #4794

Closed
twmr opened this issue Jun 19, 2018 · 8 comments
Closed

Allow filenames in _CalledFromGeneratedFile to contain "/pb2/" #4794

twmr opened this issue Jun 19, 2018 · 8 comments
Assignees

Comments

@twmr
Copy link
Contributor

twmr commented Jun 19, 2018

What language does this apply to?
python (c++ implementation)

Describe the problem you are trying to solve.

The company I work with strips the _pb2 suffix from the filenames of the generated python modules. Instead a pb2 python subpackage (e.g. companyname.pb2) is created, which denotes that the modules in this pb2 subpackage are generated by protoc (and postprocessed).

If the c++ implementation of the protobuf bindings is used, importing those generated modules does not work:

    652 
    653     def __new__(cls, name, index, number, type=None, options=None):
--> 654       _message.Message._CheckCalledFromGeneratedFile()
    655       # There is no way we can build a complete EnumValueDescriptor with the
    656       # given parameters (the name of the Enum is not known, for example).

TypeError: Descriptors should not be created directly, but only retrieved from their parent.

Describe the solution you'd like
Given that a similar bug/feature request was recently fixed (#4262), I would like that _CalledFromGeneratedFile returns true when the filename contains the string "/pb2/".

Describe alternatives you've considered

Additional context
Add any other context or screenshots about the feature request here.

@twmr twmr changed the title Allow filenames in _CalledFromGeneratedFile to container "/pb2/" Allow filenames in _CalledFromGeneratedFile to contain "/pb2/" Jun 19, 2018
@anandolee
Copy link
Contributor

anandolee commented Jun 21, 2018

Do you know why your company strips the _pb2 suffix?

#4262 is for cython which is a common issue. I don't think it make sense to make a fix if it is only an issue that caused by your company's change.

@twmr
Copy link
Contributor Author

twmr commented Jun 25, 2018

Yes, I know. It was me who created this companyname.pb2.xxx package hierarchy format for our compiled proto-files years ago.

I created this convention because I think that this hierarchy is more pythonic than having modules suffixed with _pb2.

@twmr
Copy link
Contributor Author

twmr commented Jun 27, 2018

There is a comment in https://github.com/google/protobuf/blob/HEAD/python/google/protobuf/pyext/descriptor.cc#L94

suggesting to completely remove the (hacky) _CalledFromGeneratedFile function. Are there any updates on this?

@twmr
Copy link
Contributor Author

twmr commented Jul 3, 2018

@anandolee what do you think about this feature request? Does it make sense if I come up with a PR?

@anandolee
Copy link
Contributor

anandolee commented Jul 19, 2018

I agree to remove this function, it is a behavior diffs between pure python and c extension as well.

Add @amauryfa on the TODO-removal, do we still have something to be worried for the removal?

@twmr
Copy link
Contributor Author

twmr commented Sep 13, 2018

FYI: I've started to work on the removal of _CalledFromGeneratedFile in twmr@e0ae302 (there are some python tests that fail with this change: https://travis-ci.org/thisch/protobuf/jobs/428294435)

@anandolee
Copy link
Contributor

Those tests are for test coverage and also mark the behavior diffs of pure python and cpp extension. Could remove the failure tests or change to new behavior.

@anandolee
Copy link
Contributor

Close it as PR #5171 is closed. Feel free to reopen it is still needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants