Skip to content

Commit

Permalink
Reapply changes to default stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
kedder committed Aug 22, 2023
1 parent c06deed commit f2f9af8
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 51 deletions.
9 changes: 9 additions & 0 deletions src/zope-stubs/interface/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
from zope.interface.declarations import Declaration as Declaration, alsoProvides as alsoProvides, classImplements as classImplements, classImplementsFirst as classImplementsFirst, classImplementsOnly as classImplementsOnly, directlyProvidedBy as directlyProvidedBy, directlyProvides as directlyProvides, implementedBy as implementedBy, implementer as implementer, implementer_only as implementer_only, moduleProvides as moduleProvides, noLongerProvides as noLongerProvides, providedBy as providedBy, provider as provider
from zope.interface.interface import Attribute as Attribute, Interface as Interface, interfacemethod as interfacemethod, invariant as invariant, taggedValue as taggedValue
from zope.interface.exceptions import Invalid as Invalid, DoesNotImplement as DoesNotImplement, BrokenImplementation as BrokenImplementation, Inval
from zope.interface import adapter as adapter
from zope.interface import advice as advice
from zope.interface import interfaces as interfaces
from zope.interface import declarations as declarations
from zope.interface import document as document
from zope.interface import exceptions as exceptions
from zope.interface import verify as verify
from zope.interface import ro as ro
2 changes: 1 addition & 1 deletion src/zope-stubs/interface/common/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ class ABCInterfaceClass(InterfaceClass):
def getABC(self): ...
def getRegisteredConformers(self): ...

ABCInterface: Incomplete
class ABCInterface(metaclass=ABCInterfaceClass): ...
79 changes: 48 additions & 31 deletions src/zope-stubs/interface/common/mapping.pyi
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
from _typeshed import Incomplete
from zope.interface import Interface as Interface
from zope.interface.common import collections as collections

class IItemMapping(Interface):
def __getitem__(key) -> None: ...

class IReadMapping(collections.IContainer, IItemMapping):
def get(key, default: Incomplete | None = ...) -> None: ...
def __contains__(key) -> bool: ...

class IWriteMapping(Interface):
def __delitem__(key) -> None: ...
def __setitem__(key, value) -> None: ...

class IEnumerableMapping(collections.ISized, IReadMapping):
def keys() -> None: ...
def __iter__(): ...
def values() -> None: ...
def items() -> None: ...

class IMapping(IWriteMapping, IEnumerableMapping): ...
class IIterableMapping(IEnumerableMapping): ...
# Stubs for zope.interface.common.mapping (Python 3.6)
#
# NOTE: This dynamically typed stub was automatically generated by stubgen.

from typing import Any, Optional, Union, TypeVar, Generic, Iterable, Iterator, overload
from zope.interface import Interface

T = TypeVar('T')
KT = TypeVar('KT')
VT = TypeVar('VT')

class IItemMapping(Interface, Generic[KT, VT]):
def __getitem__(key: KT) -> VT: ...

class IReadMapping(IItemMapping[KT, VT]):
@overload
def get(self, k: KT) -> Optional[VT]: ...
@overload
def get(self, k: KT, default: Union[VT, T]) -> Union[VT, T]: ...
# def get(key: KT, default: Optional[VT] = ...) -> VT: ...
def __contains__(key: KT) -> bool: ...

class IWriteMapping(Interface, Generic[KT, VT]):
def __delitem__(key: KT) -> None: ...
def __setitem__(key: KT, value: VT) -> None: ...

class IEnumerableMapping(IReadMapping[KT, VT]):
def keys() -> Iterable[KT]: ...
def __iter__() -> Iterator[VT]: ...
def values() -> Iterable[VT]: ...
def items() -> Iterable[tuple[KT, VT]]: ...
def __len__() -> int: ...

class IMapping(IWriteMapping[KT, VT], IEnumerableMapping[KT, VT]): ...

class IIterableMapping(IEnumerableMapping[KT, VT]):
def iterkeys() -> Iterable[KT]: ...
def itervalues() -> Iterable[VT]: ...
def iteritems() -> Iterable[tuple[KT, VT]]: ...

class IClonableMapping(Interface):
def copy() -> None: ...
def copy() -> IClonableMapping: ...

class IExtendedReadMapping(IIterableMapping): ...
class IExtendedReadMapping(IIterableMapping[KT, VT]):
def has_key(key: KT) -> bool: ...

class IExtendedWriteMapping(IWriteMapping):
class IExtendedWriteMapping(IWriteMapping[KT, VT]):
def clear() -> None: ...
def update(d) -> None: ...
def setdefault(key, default: Incomplete | None = ...) -> None: ...
def pop(k, default: Incomplete | None = ...) -> None: ...
def popitem() -> None: ...
def update(d: Any) -> None: ...
def setdefault(key: KT, default: Optional[VT] = ...) -> None: ...
def pop(k: KT, *args: Any) -> None: ...
def popitem() -> VT: ...

class IFullMapping(collections.IMutableMapping, IExtendedReadMapping, IExtendedWriteMapping, IClonableMapping, IMapping): ...
class IFullMapping(IExtendedReadMapping[KT, VT], IExtendedWriteMapping[KT, VT], IClonableMapping[KT, VT], IMapping[KT, VT]): ...
16 changes: 9 additions & 7 deletions src/zope-stubs/interface/interface.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class Element:
SpecificationBasePy = object

class SpecificationBase:
def providedBy(self, ob): ...
def implementedBy(self, cls): ...
def isOrExtends(self, interface): ...
def providedBy(self, ob) -> bool: ...
def implementedBy(self, cls) -> bool: ...
def isOrExtends(self, interface) -> bool: ...
__call__ = isOrExtends

class NameAndModuleComparisonMixin:
Expand All @@ -28,7 +28,7 @@ class NameAndModuleComparisonMixin:
def __gt__(self, other): ...
def __ge__(self, other): ...

class InterfaceBase(NameAndModuleComparisonMixin, SpecificationBasePy):
class InterfaceBase(NameAndModuleComparisonMixin, SpecificationBase):
__name__: Incomplete
__ibmodule__: Incomplete
def __init__(self, name: Incomplete | None = ..., module: Incomplete | None = ...) -> None: ...
Expand All @@ -43,8 +43,6 @@ class InterfaceBase(NameAndModuleComparisonMixin, SpecificationBasePy):
adapter_hooks: Incomplete

class Specification(SpecificationBase):
isOrExtends: Incomplete
providedBy: Incomplete
__iro__: Incomplete
__sro__: Incomplete
__bases__: Incomplete
Expand All @@ -64,7 +62,8 @@ class _InterfaceMetaClass(type):
@property
def __module__(cls): ...

class InterfaceClass(_InterfaceClassBase):

class InterfaceClass(type, Element, InterfaceBase, Specification):
def __new__(cls, name: Incomplete | None = ..., bases=..., attrs: Incomplete | None = ..., __doc__: Incomplete | None = ..., __module__: Incomplete | None = ...): ...
__identifier__: Incomplete
def __init__(self, name, bases=..., attrs: Incomplete | None = ..., __doc__: Incomplete | None = ..., __module__: Incomplete | None = ...) -> None: ...
Expand Down Expand Up @@ -99,3 +98,6 @@ class Method(Attribute):
def __call__(self, *args, **kw) -> None: ...
def getSignatureInfo(self): ...
def getSignatureString(self): ...


class Interface(metaclass=InterfaceClass): ...
11 changes: 8 additions & 3 deletions src/zope-stubs/interface/interfaces.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ class IMethod(IAttribute):
def getSignatureString() -> None: ...

class ISpecification(Interface):
def providedBy(object) -> None: ...
def implementedBy(class_) -> None: ...
def isOrExtends(other) -> None: ...
@staticmethod
def providedBy(object) -> bool: ...
@staticmethod
def implementedBy(class_) -> bool: ...
@staticmethod
def isOrExtends(other) -> bool: ...
@staticmethod
def extends(other, strict: bool = ...) -> None: ...
@staticmethod
def weakref(callback: Incomplete | None = ...) -> None: ...
__bases__: Incomplete
__sro__: Incomplete
Expand Down
22 changes: 13 additions & 9 deletions src/zope-stubs/interface/registry.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from _typeshed import Incomplete
from collections.abc import Generator
from typing import Iterator, Optional, Type, TypeVar, Tuple

T = TypeVar("T")


class _UnhashableComponentCounter:
def __init__(self, otherdict) -> None: ...
Expand All @@ -20,22 +24,22 @@ class Components:
def registerUtility(self, component: Incomplete | None = ..., provided: Incomplete | None = ..., name: str = ..., info: str = ..., event: bool = ..., factory: Incomplete | None = ...) -> None: ...
def unregisterUtility(self, component: Incomplete | None = ..., provided: Incomplete | None = ..., name: str = ..., factory: Incomplete | None = ...): ...
def registeredUtilities(self) -> Generator[Incomplete, None, None]: ...
def queryUtility(self, provided, name: str = ..., default: Incomplete | None = ...): ...
def getUtility(self, provided, name: str = ...): ...
def getUtilitiesFor(self, interface) -> Generator[Incomplete, Incomplete, None]: ...
def queryUtility(self, provided: Type[T], name: str = ..., default: Incomplete | None = ...) -> Optional[T]: ...
def getUtility(self, provided: Type[T], name: str = ...) -> T: ...
def getUtilitiesFor(self, interface: Type[T]) -> Iterator[Tuple[str, T]]: ...
def getAllUtilitiesRegisteredFor(self, interface): ...
def registerAdapter(self, factory, required: Incomplete | None = ..., provided: Incomplete | None = ..., name: str = ..., info: str = ..., event: bool = ...) -> None: ...
def unregisterAdapter(self, factory: Incomplete | None = ..., required: Incomplete | None = ..., provided: Incomplete | None = ..., name: str = ...): ...
def registeredAdapters(self) -> Generator[Incomplete, None, None]: ...
def queryAdapter(self, object, interface, name: str = ..., default: Incomplete | None = ...): ...
def getAdapter(self, object, interface, name: str = ...): ...
def queryMultiAdapter(self, objects, interface, name: str = ..., default: Incomplete | None = ...): ...
def getMultiAdapter(self, objects, interface, name: str = ...): ...
def getAdapters(self, objects, provided) -> Generator[Incomplete, None, None]: ...
def queryAdapter(self, object, interface: Type[T], name: str = ..., default: Incomplete | None = ...) -> Optional[T]: ...
def getAdapter(self, object, interface: Type[T], name: str = ...) -> T: ...
def queryMultiAdapter(self, objects, interface: Type[T], name: str = ..., default: Incomplete | None = ...) -> Optional[T]: ...
def getMultiAdapter(self, objects, interface: Type[T], name: str = ...) -> T: ...
def getAdapters(self, objects, provided: Type[T]) -> Iterator[Tuple[str, T]]: ...
def registerSubscriptionAdapter(self, factory, required: Incomplete | None = ..., provided: Incomplete | None = ..., name: str = ..., info: str = ..., event: bool = ...) -> None: ...
def registeredSubscriptionAdapters(self) -> Generator[Incomplete, None, None]: ...
def unregisterSubscriptionAdapter(self, factory: Incomplete | None = ..., required: Incomplete | None = ..., provided: Incomplete | None = ..., name: str = ...): ...
def subscribers(self, objects, provided): ...
def subscribers(self, objects, provided: Type[T]) -> T: ...
def registerHandler(self, factory, required: Incomplete | None = ..., name: str = ..., info: str = ..., event: bool = ...) -> None: ...
def registeredHandlers(self) -> Generator[Incomplete, None, None]: ...
def unregisterHandler(self, factory: Incomplete | None = ..., required: Incomplete | None = ..., name: str = ...): ...
Expand Down
20 changes: 20 additions & 0 deletions tests/samples/custom_sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Override a sequence interface"""

from zope.interface.common import sequence

class ICustomSequence(sequence.IFiniteSequence):
def iterator(first, count):
pass

def size() -> int:
pass

seq = object()
assert ICustomSequence.providedBy(seq)
reveal_type(seq.size())

"""
<output>
custom_sequence.py:14: note: Revealed type is "builtins.int"
</output>
"""

0 comments on commit f2f9af8

Please sign in to comment.