Skip to content

Commit

Permalink
Adapt to autogenerated stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
kedder committed Jan 13, 2019
1 parent cf92968 commit e70d505
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/mypy_zope/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def analyze(function_ctx: FunctionContext) -> Type:
api = function_ctx.api
deftype = function_ctx.default_return_type

if self._is_subclass(deftype, 'zope.interface.Attribute'):
if self._is_subclass(deftype, 'zope.interface.interface.Attribute'):
return self._get_schema_field_type(
deftype, function_ctx.arg_names, function_ctx.args, api)
if self._is_subclass(deftype, 'zope.schema.fieldproperty.FieldProperty'):
Expand Down Expand Up @@ -154,7 +154,7 @@ def analyze(classdef_ctx: ClassDefContext) -> None:
for iface_arg in decor.args:
apply_interface(iface_arg, classdef_ctx.cls.info, api)

if fullname=='zope.interface.implementer':
if fullname=='zope.interface.declarations.implementer':
return analyze
return None

Expand Down Expand Up @@ -191,7 +191,7 @@ def analyze_subinterface(classdef_ctx: ClassDefContext) -> None:
cls_md = self._get_metadata(cls_info)
cls_md['is_interface'] = True

if fullname == 'zope.interface.Interface':
if fullname == 'zope.interface.interface.Interface':
return analyze_direct

return analyze_subinterface
Expand Down Expand Up @@ -233,7 +233,7 @@ def analyze(classdef_ctx: ClassDefContext) -> None:

# If we are dealing with an interface, massage it a bit, e.g.
# inject `self` argument to all methods
directiface = 'zope.interface.Interface' in [b.type.fullname() for b in info.bases]
directiface = 'zope.interface.interface.Interface' in [b.type.fullname() for b in info.bases]
subinterface = any(self._is_interface(b.type) for b in info.bases)
if directiface or subinterface:
self._analyze_zope_interface(classdef_ctx.cls)
Expand All @@ -246,7 +246,7 @@ def analyze(classdef_ctx: ClassDefContext) -> None:
self._analyze_implementation(classdef_ctx.cls, iface_exprs, classdef_ctx.api)
return

if fullname == 'zope.interface.Interface':
if fullname == 'zope.interface.interface.Interface':
return analyze_interface_base

return analyze
Expand Down
7 changes: 3 additions & 4 deletions src/mypy_zope/stubs/zope/interface/interface.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# NOTE: This dynamically typed stub was automatically generated by stubgen.

from typing import Any, Optional
from zope.interface._zope_interface_coptimizations import InterfaceBase, SpecificationBase

CO_VARARGS: int
CO_VARKEYWORDS: int
Expand Down Expand Up @@ -52,7 +51,7 @@ class Specification(SpecificationBase):
def weakref(self, callback: Optional[Any] = ...): ...
def get(self, name: Any, default: Optional[Any] = ...): ...

class InterfaceClass(Element, InterfaceBase, Specification):
class InterfaceClass(type, Element, InterfaceBase, Specification):
__module__: Any = ...
__identifier__: Any = ...
def __init__(self, name: Any, bases: Any = ..., attrs: Optional[Any] = ..., __doc__: Optional[Any] = ..., __module__: Optional[Any] = ...) -> None: ...
Expand All @@ -63,7 +62,7 @@ class InterfaceClass(Element, InterfaceBase, Specification):
def __iter__(self): ...
def namesAndDescriptions(self, all: bool = ...): ...
def getDescriptionFor(self, name: Any): ...
__getitem__: Any = ...
def __getitem__(self, key, default: Optional[Any] = ...) -> Any: ...
def __contains__(self, name: Any): ...
def direct(self, name: Any): ...
def queryDescriptionFor(self, name: Any, default: Optional[Any] = ...): ...
Expand All @@ -77,7 +76,7 @@ class InterfaceClass(Element, InterfaceBase, Specification):
def __gt__(self, other: Any): ...
def __ge__(self, other: Any): ...

Interface: Any
class Interface(metaclass=InterfaceClass): ...

class Attribute(Element):
interface: Any = ...
Expand Down
4 changes: 2 additions & 2 deletions tests/samples/bad_mro.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def main() -> None:
"""
<output>
bad_mro.py:19: error: Unable to calculate a consistent MRO: cannot merge class hierarchies:
bad_mro.py:19: error: -> ['__main__.Crocodile', '__main__.Reptilia', '__main__.Swimmable', '__main__.ISwimmable', '__main__.IReptilia', '__main__.ICreature', 'zope.interface.Interface', 'builtins.object']
bad_mro.py:19: error: -> ['__main__.ICrocodile', '__main__.ICreature', '__main__.ISwimmable', 'zope.interface.Interface', 'builtins.object']
bad_mro.py:19: error: -> ['__main__.Crocodile', '__main__.Reptilia', '__main__.Swimmable', '__main__.ISwimmable', '__main__.IReptilia', '__main__.ICreature', 'zope.interface.interface.Interface', 'builtins.object']
bad_mro.py:19: error: -> ['__main__.ICrocodile', '__main__.ICreature', '__main__.ISwimmable', 'zope.interface.interface.Interface', 'builtins.object']
</output>
"""

0 comments on commit e70d505

Please sign in to comment.