Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions betterproto2/src/betterproto2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ def _betterproto(cls: type[Self]) -> ProtoClassMetadata: # type: ignore
try:
return cls._betterproto_meta
except AttributeError:
if cls is Message:
# We can't generate metadata for the base class, only subclasses.
return None # type: ignore
cls._betterproto_meta = ProtoClassMetadata(cls)
return cls._betterproto_meta

Expand Down
8 changes: 4 additions & 4 deletions betterproto2/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ message Test {
}
```

You can add multiple `.proto` files to the test case, as long as one file matches the directory name.
You can add multiple `.proto` files to the test case, as long as one file matches the directory name.

### json

Expand Down Expand Up @@ -64,11 +64,11 @@ The following tests are automatically executed for all cases:
- [x] Can the generated python code be imported?
- [x] Can the generated message class be instantiated?
- [x] Is the generated code compatible with the Google's `grpc_tools.protoc` implementation?
- _when `.json` is present_
- _when `.json` is present_

## Running the tests

- `pipenv run generate`
- `pipenv run get-local-compiled-tests`
This generates:
- `betterproto/tests/output_betterproto` — *the plugin generated python classes*
- `betterproto/tests/output_reference` — *reference implementation classes*
Expand All @@ -88,4 +88,4 @@ betterproto/tests/test_inputs.py ..x...x..x...x.X........xx........x.....x......
- `x` — XFAIL: expected failure
- `X` — XPASS: expected failure, but still passed

Test cases marked for expected failure are declared in [inputs/config.py](inputs/config.py)
Test cases marked for expected failure are declared in [inputs/config.py](inputs/config.py)
10 changes: 10 additions & 0 deletions betterproto2/tests/test_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,13 @@ def test_escaping(requires_grpclib) -> None:
Simple quotes are not escaped "
"""
)


def test_help(requires_grpclib) -> None:
"""Test that help(Foo) doesn't trigger an error."""
from .outputs.documentation.documentation import Test

# help(Test) triggers help(Message)
# which inspects the class attribute Message._betterproto
# which is only supposed to be defined on subclasses of Message.
help(Test)