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

Bug in _package_info.py compile #491

Open
aurelien78 opened this issue Oct 5, 2024 · 0 comments
Open

Bug in _package_info.py compile #491

aurelien78 opened this issue Oct 5, 2024 · 0 comments
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@aurelien78
Copy link

On version 1.24.0, in _package_info.py compile() methode line 36 there is :

module_name = module.__name__ if hasattr(module, __name__) else ""

I think it should be :

module_name = module.__name__ if hasattr(module, "__name__") else ""

Furthermore, if we are dealing with packages, I think the whole code should be :

    # Pull a reference to the module where this class is being
    # declared.
    module = sys.modules.get(attrs.get("__module__"))
    module_name = module.__name__ if hasattr(module, "__name__") else ""
    if '.' in module_name:
        parts = module_name.split('.')
        package_name =  '.'.join(parts[:-1])
    else:
        package_name = module_name
    proto_module = getattr(module, "__protobuf__", object())

    # A package should be present; get the marshal from there.
    # TODO: Revert to empty string as a package value after protobuf fix.
    # When package is empty, upb based protobuf fails with an
    # "TypeError: Couldn't build proto file into descriptor pool: invalid name: empty part ()' means"
    # during an attempt to add to descriptor pool.
    package = getattr(
        proto_module, "package", package_name if package_name else "_default_package"
    )
    marshal = Marshal(name=getattr(proto_module, "marshal", package))

    # Done; return the data.
    return (package, marshal)

@aurelien78 aurelien78 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

1 participant