Shoobx / mypy-zope

Plugin for mypy to support zope.interface
MIT License
39 stars 13 forks source link

Regression in upcoming mypy 0.990 #82

Closed arnimarj closed 1 year ago

arnimarj commented 2 years ago

Hi. I was testing the upcoming mypy release and it seems to be emitting new warning for interface definitions:

import zope.interface

class IZomething(zope.interface.Interface):
    def Query(a: str, b: str) -> list[int]:
        pass

gives:

$ mypy --config=mypy.ini int.py 
int.py:5: error: Missing return statement  [empty-body]
Found 1 error in 1 file (checked 1 source file)

Replacing the function body with ellipses silences the warning. Perhaps that should be the preferred way to define interfaces moving forward?

arnimarj commented 1 year ago

This is probably caused by https://github.com/python/mypy/pull/13729

kedder commented 1 year ago

It doesn't seem like ellipses help here (I'm getting the same error if I replace pass with ...). And clearly we don't want these errors for zope interface methods. Trying to figure out the workaround.

kedder commented 1 year ago

That particular issue was easy to work around by explicitly marking interface methods as "abstract". However now mypy complains about not being able to instantiate abstract classes when we do "adaptation pattern". And there seem to be some deeper issue in mypy that prevents a "nice" solution for this right now. Filed https://github.com/python/mypy/issues/14106, waiting or some response.