[PATCH 14 of 24 yams V2] [mypy] type interfaces.py

Laurent Peuch cortex at worlddomination.be
Wed Mar 4 15:17:50 CET 2020


# HG changeset patch
# User Laurent Peuch <cortex at worlddomination.be>
# Date 1580230842 -3600
#      Tue Jan 28 18:00:42 2020 +0100
# Node ID 47dd2a02498cf7beace106c0743d2222105ed74b
# Parent  46b2e7cc98be83ade4483cc019f019bf9aefd3f2
# Available At https://hg.logilab.org/users/lpeuch/yams
#              hg pull https://hg.logilab.org/users/lpeuch/yams -r 47dd2a02498c
# EXP-Topic type_annotations
[mypy] type interfaces.py

diff --git a/yams/interfaces.py b/yams/interfaces.py
--- a/yams/interfaces.py
+++ b/yams/interfaces.py
@@ -18,10 +18,14 @@
 """Public interfaces for yams.
 
 """
-__docformat__ = "restructuredtext en"
+
+from typing import List, Any, Tuple, Iterator, Optional
+from yams.types import _SchemaType
 
 from logilab.common.interface import Interface
 
+__docformat__: str = "restructuredtext en"
+
 # remove this to avoid a dependency on rql for client code
 # from rql.interfaces import ISchema as IRQLSchema, \
 #     IRelationSchema as IRQLRelationSchema, IEntitySchema as IRQLEntitySchema
@@ -30,32 +34,32 @@ from logilab.common.interface import Int
 class ISchema(Interface):  # (IRQLSchema):
     """a schema is a collection of relation and entity schemas"""
 
-    def entities(self, schema=None):
+    def entities(self, schema: Optional[_SchemaType] = None) -> List:
         """return a list of possible entity's type
 
         If schema is not None, return a list of schemas instead of types.
         """
 
-    def has_entity(self, e_type):
+    def has_entity(self, e_type) -> bool:
         """return true the type is defined in the schema
         """
 
-    def eschema(self, e_type):
+    def eschema(self, e_type) -> Any:
         """return the entity's schema for the given type
         """
 
-    def relations(self, schema=None):
+    def relations(self, schema: _SchemaType = None) -> List:
         """return the list of possible relation'types
 
         If schema is not None, return a list of schemas instead of relation's
         types.
         """
 
-    def has_relation(self, rtype):
+    def has_relation(self, rtype) -> bool:
         """return true the relation is defined in the schema
         """
 
-    def rschema(self, rtype):
+    def rschema(self, rtype) -> None:
         """return the relation schema for the given relation type
         """
 
@@ -65,14 +69,14 @@ class IRelationSchema(Interface):  # (IR
     A relation schema defines the possible types of both extremities.
     """
 
-    def associations(self, schema=None):
+    def associations(self, schema: _SchemaType = None) -> List[Tuple[Any, List[Any]]]:
         """return a list of (subject_type, [object_types]) defining between
         which types this relation may exists
 
         If schema is not None, return a list of schemas instead of type.
         """
 
-    def subjects(self, etype=None):
+    def subjects(self, etype=None) -> List:
         """return a list of types which can be subject of this relation
 
         If e_type is not None, return a list of types which can be subject of
@@ -81,7 +85,7 @@ class IRelationSchema(Interface):  # (IR
         Raise KeyError if e_type is not known
         """
 
-    def objects(self, etype=None):
+    def objects(self, etype=None) -> List:
         """return a list of types which can be object of this relation.
 
         If e_type is not None, return a list of types which can be object of
@@ -99,7 +103,7 @@ class IEntitySchema(Interface):  # (IRQL
     Attributes are defined with relations pointing to a 'final' entity
     """
 
-    def subject_relations(self):
+    def subject_relations(self) -> List:
         """return a list of relations that may have this type of entity as
         subject
 
@@ -107,7 +111,7 @@ class IEntitySchema(Interface):  # (IRQL
         types.
         """
 
-    def object_relations(self):
+    def object_relations(self) -> List:
         """return a list of relations that may have this type of entity as
         object
 
@@ -115,19 +119,19 @@ class IEntitySchema(Interface):  # (IRQL
         types.
         """
 
-    def subject_relation(self, rtype):
+    def subject_relation(self, rtype) -> Any:
         """return the relation schema for the rtype subject relation
 
         Raise KeyError if rtype is not known.
         """
 
-    def object_relation(self, rtype):
+    def object_relation(self, rtype) -> Any:
         """return the relation schema for the rtype object relation
 
         Raise KeyError if rtype is not known.
         """
 
-    def relation_definitions(self):
+    def relation_definitions(self) -> Iterator:
         """return an iterator on "real" relation definitions
 
         "real"  relations are a subset of subject relations where the
@@ -138,7 +142,7 @@ class IEntitySchema(Interface):  # (IRQL
         * schema of the destination entity type
         """
 
-    def attribute_definitions(self):
+    def attribute_definitions(self) -> Iterator:
         """return an iterator on attribute definitions
 
         attribute relations are a subset of subject relations where the
@@ -149,20 +153,20 @@ class IEntitySchema(Interface):  # (IRQL
         * schema of the destination entity type
         """
 
-    def is_final(self):
+    def is_final(self) -> bool:
         """return true if the entity is a final entity (ie cannot be used
         as subject of a relation)
         """
 
-    def constraints(self, rtype):
+    def constraints(self, rtype) -> Any:
         """return the existing constraints on the <rtype> subject relation
         """
 
-    def default(self, rtype):
+    def default(self, rtype) -> Any:
         """return the default value of a subject relation
         """
 
-    def check(self, entity):
+    def check(self, entity) -> None:
         """check the entity and raises an InvalidEntity exception if it
         contains some invalid fields (ie some constraints failed)
         """
@@ -178,5 +182,5 @@ class IVocabularyConstraint(IConstraint)
     attribute value
     """
 
-    def vocabulary(self):
+    def vocabulary(self) -> List:
         """return a list of possible values for the attribute"""



More information about the cubicweb-devel mailing list