danielgtaylor / danielgtaylor/python-betterproto

Create `__all__` to explicitly export only the important parts

オープン
#486 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
enhancement
主要言語
Python
スター
1.8k
フォーク
234
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。