Skip to content

Remove google.protobuf.Message.__new__ - #16606

Open
ethantkoenig wants to merge 1 commit into
python:mainfrom
ethantkoenig:main
Open

ethantkoenig wants to merge 1 commit into
python:mainfrom
ethantkoenig:main

Conversation

@ethantkoenig

Copy link
Copy Markdown

Message can only be instantiated with an argument-less call:

In [1]: from google.protobuf.message import Message

In [2]: Message()
Out[2]: <google.protobuf.message.Message at 0xffffa0b13be0>

In [3]: Message(x=3)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 Message(x=3)

TypeError: Message() takes no arguments

The previous __new__(*args, **kwargs) -> Self: annotation also interfere's with ty's ability to infer a ParamSpec from a generated Message subclass's constructor (as of ty verison 0.0.91):

def wrap[**P, T](callable: Callable[P, T]) -> Callable[P, T]:
    return callable


wrap(MyProtoMessage)(
    'ty accepts positional args, which are not accepted by any Message subclass',
    this_is_not_a_valid_field='ty also accepts any kwarg',
)

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

django-stubs (https://github.com/typeddjango/django-stubs)
  error: INTERNAL ERROR -- Please try using mypy master on GitHub:

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant