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

directly-instantiated types are unsupported in mypy-zope #75

Closed
jaraco opened this issue Oct 4, 2020 · 2 comments · Fixed by #76
Closed

directly-instantiated types are unsupported in mypy-zope #75

jaraco opened this issue Oct 4, 2020 · 2 comments · Fixed by #76

Comments

@jaraco
Copy link
Contributor

jaraco commented Oct 4, 2020

In Shoobx/mypy-zope#21, I learned that mypy-zope doesn't support direct invocation of an InterfaceClass such as seen here in foolscap. With Shoobx/mypy-zope#24, however, it will support the more typical metaclass syntax. Perhaps the best approach here may be to use the appropriate metaclass instantiation, something like

class RemoteInterface(metaclass=RemoteInterfaceClass): ...

(and an equivalent for Python 2).

@jaraco
Copy link
Contributor Author

jaraco commented Oct 4, 2020

I've drafted a fix, but it unfortunately doesn't work as intended. It works on Python 3, but on Python 2, the test suite fails with 23 errors similar to:

Traceback (most recent call last):
  File "/Users/jaraco/code/public/foolscap/.tox/py27/lib/python2.7/site-packages/twisted/trial/runner.py", line 531, in loadPackage
    module = modinfo.load()
  File "/Users/jaraco/code/public/foolscap/.tox/py27/lib/python2.7/site-packages/twisted/python/modules.py", line 392, in load
    return self.pathEntry.pythonPath.moduleLoader(self.name)
  File "/Users/jaraco/code/public/foolscap/.tox/py27/lib/python2.7/site-packages/twisted/python/reflect.py", line 308, in namedAny
    topLevelPackage = _importAndCheckStack(trialname)
  File "/Users/jaraco/code/public/foolscap/.tox/py27/lib/python2.7/site-packages/twisted/python/reflect.py", line 247, in _importAndCheckStack
    return __import__(importName)
  File "/Users/jaraco/code/public/foolscap/src/foolscap/test/test__versions.py", line 9, in <module>
    from foolscap.api import __version__
  File "/Users/jaraco/code/public/foolscap/src/foolscap/api.py", line 16, in <module>
    from foolscap.pb import Tub
  File "/Users/jaraco/code/public/foolscap/src/foolscap/pb.py", line 14, in <module>
    from foolscap import ipb, base32, negotiate, broker, eventual, storage
  File "/Users/jaraco/code/public/foolscap/src/foolscap/negotiate.py", line 10, in <module>
    from foolscap import broker, referenceable, vocab
  File "/Users/jaraco/code/public/foolscap/src/foolscap/broker.py", line 17, in <module>
    from foolscap import call, slicer, referenceable, copyable, remoteinterface
  File "/Users/jaraco/code/public/foolscap/src/foolscap/call.py", line 11, in <module>
    from foolscap.logging import log
  File "/Users/jaraco/code/public/foolscap/src/foolscap/logging/log.py", line 9, in <module>
    from foolscap.logging.interfaces import IIncidentReporter
  File "/Users/jaraco/code/public/foolscap/src/foolscap/logging/interfaces.py", line 3, in <module>
    from foolscap.remoteinterface import RemoteInterface
  File "/Users/jaraco/code/public/foolscap/src/foolscap/remoteinterface.py", line 416, in <module>
    """)
  File "/Users/jaraco/code/public/foolscap/.tox/py27/lib/python2.7/site-packages/six.py", line 719, in exec_
    exec("""exec _code_ in _globs_, _locs_""")
  File "<string>", line 1, in <module>
    
  File "<string>", line 1, in <module>
    
  File "/Users/jaraco/code/public/foolscap/src/foolscap/remoteinterface.py", line 39, in __init__
    rname, remote_attrs = self._parseRemoteInterface(iname, attrs)
  File "/Users/jaraco/code/public/foolscap/src/foolscap/remoteinterface.py", line 77, in _parseRemoteInterface
    IConstraint.providedBy(attrs[name]))]
  File "/Users/jaraco/code/public/foolscap/.tox/py27/lib/python2.7/site-packages/zope/interface/declarations.py", line 394, in implementedBy
    spec_name = _implements_name(cls)
  File "/Users/jaraco/code/public/foolscap/.tox/py27/lib/python2.7/site-packages/zope/interface/declarations.py", line 292, in _implements_name
    '.' + (getattr(ob, '__name__', '?') or '?')
exceptions.TypeError: unsupported operand type(s) for +: 'property' and 'str'

@jaraco
Copy link
Contributor Author

jaraco commented Oct 13, 2020

I was able to work around the issue by deriving the RemoteInterface from Interface and removing __metaclass__ from the class dict on construction (4100bdf).

@exarkun exarkun mentioned this issue Jan 15, 2021
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 a pull request may close this issue.

1 participant