Message methods not defined as positional arg only
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
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
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.
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
Makes sense. I'll hold off on changing mypy-protobuf then.