python-betterproto
python-betterproto copied to clipboard
Invalid code generated when package name contains uppercase letter
Summary
Title
Reproduction Steps
This protofile works:
// proto/test.proto
syntax = "proto3";
package p;
service Service {
rpc Method(Empty) returns (Empty) {}
}
message Empty {}
This doesn't:
// proto/test.proto
syntax = "proto3";
package P;
service Service {
rpc Method(Empty) returns (Empty) {}
}
message Empty {}
With the latter, betterproto compiles to this:
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: test.proto
# plugin: python-betterproto
# This file has been @generated
from dataclasses import dataclass
from typing import (
TYPE_CHECKING,
Dict,
Optional,
)
import betterproto
import grpclib
from betterproto.grpc.grpclib_server import ServiceBase
from .. import PEmpty as _PEmpty__
# [...]
The from .. import PEmpty
is invalid import as nothing exists in the parent package.
Command used:
python3 -m grpc_tools.protoc --proto_path=./proto/ --python_betterproto_out=./proto/ proto/*.proto
Python environment (output of pip freeze
):
betterproto @ git+https://github.com/danielgtaylor/python-betterproto@5666393f9d10e13609d8eeac8d1ab3815dce5fd6
black==24.2.0
click==8.1.7
grpcio==1.62.1
grpcio-tools==1.62.1
grpclib==0.4.7
h2==4.1.0
hpack==4.0.0
hyperframe==6.0.1
isort==5.13.2
Jinja2==3.1.3
MarkupSafe==2.1.5
multidict==6.0.5
mypy-extensions==1.0.0
nodeenv==1.8.0
packaging==24.0
pathspec==0.12.1
platformdirs==4.2.0
protobuf==4.25.3
pyright==1.1.353
python-dateutil==2.9.0.post0
six==1.16.0
typing_extensions==4.10.0
Expected Results
Correct code generated
Actual Results
Incorrect code generated
System Information
libprotoc 3.12.4 Python 3.11.0rc1 Name: betterproto Version: 2.0.0b6 Summary: A better Protobuf / gRPC generator & library Home-page: https://github.com/danielgtaylor/python-betterproto Author: Daniel G. Taylor Author-email: [email protected] License: MIT Location: <REDACTED> Requires: grpclib, python-dateutil, typing-extensions Required-by:
Checklist
- [X] I have searched the issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have verified this issue occurs on the latest prelease of betterproto which can be installed using
pip install -U --pre betterproto
, if possible.