Commit c839abdd authored by Nsukami Patrick's avatar Nsukami Patrick
Browse files

[mypy]: Fix various errors

Updates:
--------
- Annotate cardinality attribute as a Union of nullobject, str, None.
- assert cardinality is an instance of str if not an instance of nullobject


To fix the following errors:
----------------------------
yams/buildobjs.py:1071: error: Incompatible types in assignment (expression has type "str", variable has type "nullobject")  [assignment]
		    self.cardinality = "?1"
				       ^
yams/buildobjs.py:1073: error: Incompatible types in assignment (expression has type "str", variable has type "nullobject")  [assignment]
		    self.cardinality = "**"
				       ^
yams/buildobjs.py:1075: error: Argument 1 to "len" has incompatible type "nullobject"; expected "Sized"  [arg-type]
		assert len(cardinality) == 2
			   ^
yams/buildobjs.py:1076: error: Value of type "nullobject" is not indexable  [index]
		assert cardinality[0] in "1?+*"
		       ^
yams/buildobjs.py:1077: error: Value of type "nullobject" is not indexable  [index]
		assert cardinality[1] in "1?+*"
parent 86a47939509a
Pipeline #100254 passed with stages
in 1 minute and 38 seconds
......@@ -23,7 +23,7 @@ from copy import copy
from typing import Any, Generator, Tuple, Type, Union, Dict, Sequence, Iterable, Set, cast, TypeVar
from logilab.common import attrdict, deprecation
from logilab.common import attrdict, deprecation, nullobject
import yams.types as yams_types
......@@ -947,7 +947,7 @@ class RelationDefinition(Definition):
subject = MARKER
object = MARKER
cardinality = MARKER
cardinality: Union[nullobject, str, None] = MARKER
constraints = MARKER
symmetric = MARKER
inlined = MARKER
......@@ -1072,6 +1072,7 @@ class RelationDefinition(Definition):
else:
self.cardinality = "**"
else:
assert isinstance(cardinality, str)
assert len(cardinality) == 2
assert cardinality[0] in "1?+*"
assert cardinality[1] in "1?+*"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment