Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referenceable convention not recognized by mypy #78

Open
jaraco opened this issue Nov 29, 2020 · 1 comment
Open

Referenceable convention not recognized by mypy #78

jaraco opened this issue Nov 29, 2020 · 1 comment

Comments

@jaraco
Copy link
Contributor

jaraco commented Nov 29, 2020

In this comment, I isolated an issue where mypy static analysis checks are failing on a foolscap Referenceable RemoteInterface. Given this minimal implementation:

# remote.py
from foolscap.api import RemoteInterface, Referenceable
from zope.interface import implementer


class RIBucketWriter(RemoteInterface):
    """ Objects of this kind live on the server side. """
    def write(offset=None, data=None):
        return None


@implementer(RIBucketWriter)
class BucketWriter(Referenceable):
    def remote_write(self, offset, data):
        pass

and this mypy configuration:

[mypy]
ignore_missing_imports = True
plugins=mypy_zope:plugin

Then, creating an environment with unmerged branches of mypy-zope and foolscap:

test $ python -m venv env
test $ env/bin/pip install -q mypy-zope@git+https://github.com/jaraco/mypy-zope@bugfix/21-InterfaceClass-subclass foolscap@git+https://github.com/jaraco/foolscap@bugfix/75-use-metaclass

Attempting to run mypy on that simple BucketWriter produces this error:

test $ env/bin/mypy remote.py
remote.py:18: error: 'BucketWriter' is missing following 'RIBucketWriter' interface members: write.
Found 1 error in 1 file (checked 1 source file)

It seems mypy is unaware of the contract that a Referenceable adds providing the required interface but with method names replaced with remote_ prefixed.

Presumably the proper fix would be to add mypy support (plugin) for these Referenceable objects.

@jaraco
Copy link
Contributor Author

jaraco commented Nov 29, 2020

Adding # type: ignore after the class definition of the Referenceable subclass seems to suppress the error.

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

No branches or pull requests

1 participant