Skip to content

Pyright complains reportAttributeAccessIssue on generated class fields (pydantic) #161

@wuyuanyi135

Description

@wuyuanyi135

Summary

Pyright complains reportAttributeAccessIssue on generated class fields (pydantic)

Reproduction Steps

sample proto

syntax = "proto3";
import "nanopb.proto";

message DataMessage {
  int32 battery_mv = 1;
  int32 boot_count = 2;
  uint64 timestamp = 3;

  float temperature = 10;
  float a_x = 11;
  float a_y = 12;
  float a_z = 13;
  float z_angle = 14;
  float v_rms = 15;
  float v_x = 16;
  float v_y = 17;
  float v_z = 18;
  bytes vibration_raw_data = 19 [(nanopb).type = FT_POINTER];

}

generated with

python -m grpc.tools.protoc -I ... --python_betterproto2_opt=pydantic_dataclasses --python_betterproto2_out=out *.proto

Gives a bunch of pyright error such as Cannot access attribute "timestamp" for class "PydanticDataclass"   Attribute "timestamp" is unknown

Image

The program runs fine. I have to put ignore on each access or on the top to disable the check. Is there any instruction how I can configure the generated file working with pyright?

Expected Results

No pyright error on correct code

Actual Results

pyright error

System Information

libprotoc 31.1
Python 3.13.7
betterproto2 v0.9.1

Checklist

  • I have searched the issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have verified this issue occurs on the latest prelease of betterproto which can be installed using pip install -U --pre betterproto, if possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions