danielgtaylor / danielgtaylor/python-betterproto

Create `__all__` to explicitly export only the important parts

Open
#486 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
1.8k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

Currently, it generates the following:
```py
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: example.proto
# plugin: python-betterproto
from dataclasses import dataclass

import betterproto

@dataclass
class Greeting(betterproto.Message):
"""Greeting represents a message you can tell a user."""

message: str = betterproto.string_field(1)
```

If you try to import from it, you'll get suggestions for importing `dataclass`, `betterproto` and `Greeting`.

Those first two, though, aren't meant to be re-exported there, only `Greeting` is supposed to be importable.

By generating with an `__all__ = ["Greeting"]`, Python would know that the only thing it's supposed to import is `Greeting`:

```py
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: example.proto
# plugin: python-betterproto

__all__ = ["Greeting"]

from dataclasses import dataclass

import betterproto

@dataclass
class Greeting(betterproto.Message):
"""Greeting represents a message you can tell a user."""

message: str = betterproto.string_field(1)
```

https://docs.python.org/3/tutorial/modules.html#importing-from-a-package
https://pep8.org/#module-level-dunder-names

Contributor guide

Open the contributing guide

Research direction

The issue targets the generated Python module and its public exports. Locate the generator entry point that assembles this module, then inspect any existing generator tests or fixtures before changing output. Done means generated modules contain an __all__ listing only intended message and service symbols, with tests covering the resulting imports.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.