protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Message methods not defined as positional arg only

Open aidandj opened this issue 2 months ago • 4 comments

What version of protobuf and what language are you using? Version: 33.1 Language: Python

What operating system (Linux, Windows, ...) and version? OSX

What runtime / compiler are you using (e.g., python version or gcc version) Python 3.14

What did you do? Python base message class defined here has certain methods HasField, ClearField etc, defined as functions with keyword arguments. But in reality they are positional args only.

What did you expect to see

Function stubs defined as HasField(self, field_name, /) indicating that they are positional only arguments

aidandj avatar Nov 13 '25 18:11 aidandj

This seems to be a persistent problem all over our upb and C++ extensions, where we use METH_O instead of more user-friendly options. https://llllllllll.github.io/c-extension-tutorial/fancy-argument-parsing.html describes this well:

METH_O is convenient for quickly testing a function, but Python programmers are used to more expressive argument passing

This does seem like a real issue, but a relatively minor annoyance that we likely won't be able to prioritize immediately

mkruskal-google avatar Nov 15 '25 05:11 mkruskal-google

Do you have an idea of whether you would update the stub definitions, or change the bindings to support kwarg as well? I'm making some changes in mypy-protobuf, and wouldn't want to mark the stubs as positional only, to have it change in the future.

aidandj avatar Nov 15 '25 05:11 aidandj

I think we would most likely fix the bindings to support kwargs like in our pure python implementation, rather than break the pure python ones. I'm not sure when we will be able to get to this, but we'll put in on a backlog for prioritization

mkruskal-google avatar Nov 18 '25 18:11 mkruskal-google

Makes sense. I'll hold off on changing mypy-protobuf then.

aidandj avatar Nov 18 '25 19:11 aidandj