Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
yams
Commits
649e6df93853
Commit
c54f16b6
authored
Apr 29, 2020
by
Laurent Peuch
Browse files
WIP: [types] removed Union[str, 'RelationSchema'] to only RelationSchema
parent
12e0716ebe7d
Changes
1
Hide whitespace changes
Inline
Side-by-side
yams/schema.py
View file @
649e6df9
...
...
@@ -255,8 +255,8 @@ class EntitySchema(PermissionMixIn, ERSchema):
if
relation_definition
is
not
None
:
# quick access to bounded relation schemas
self
.
_subject_relations
:
Dict
[
Union
[
str
,
"RelationSchema"
]
,
"RelationSchema"
]
=
{}
self
.
_object_relations
:
Dict
[
Union
[
str
,
"RelationSchema"
]
,
"RelationSchema"
]
=
{}
self
.
_subject_relations
:
Dict
[
"RelationSchema"
,
"RelationSchema"
]
=
{}
self
.
_object_relations
:
Dict
[
"RelationSchema"
,
"RelationSchema"
]
=
{}
self
.
_specialized_type
=
relation_definition
.
specialized_type
self
.
_specialized_by
=
relation_definition
.
specialized_by
self
.
final
:
bool
=
self
.
type
in
BASE_TYPES
...
...
@@ -457,18 +457,18 @@ class EntitySchema(PermissionMixIn, ERSchema):
for
relation_schema
in
self
.
object_relations
():
yield
relation_schema
,
relation_schema
.
subjects
(
self
),
"object"
@
deprecation
.
argument_renamed
(
old_name
=
"rtype"
,
new_name
=
"relation_
type
"
)
def
destination
(
self
,
relation_
type
:
Union
[
str
,
"RelationSchema"
]
)
->
"EntitySchema"
:
@
deprecation
.
argument_renamed
(
old_name
=
"rtype"
,
new_name
=
"relation_
schema
"
)
def
destination
(
self
,
relation_
schema
:
"RelationSchema"
)
->
"EntitySchema"
:
"""return the type or schema of entities related by the given subject relation
`relation_
type
` is expected to be a non ambiguous relation
`relation_
schema
` is expected to be a non ambiguous relation
"""
relation_schema
=
self
.
_subject_relations
[
relation_
type
]
relation_schema
=
self
.
_subject_relations
[
relation_
schema
]
object_types
=
relation_schema
.
objects
(
self
.
type
)
assert
len
(
object_types
)
==
1
,
(
self
.
type
,
str
(
relation_
type
),
str
(
relation_
schema
),
[
str
(
ot
)
for
ot
in
object_types
],
)
...
...
@@ -571,7 +571,9 @@ class EntitySchema(PermissionMixIn, ERSchema):
"""return metadata's relation schema if this entity has the given
`metadata` field for the given `attribute` attribute
"""
return
self
.
_subject_relations
.
get
(
"%s_%s"
%
(
attribute
,
metadata
))
return
self
.
_subject_relations
.
get
(
self
.
schema
.
relation_schema_for
(
"%s_%s"
%
(
attribute
,
metadata
))
)
@
deprecation
.
argument_renamed
(
old_name
=
"attr"
,
new_name
=
"attribute"
)
def
is_metadata
(
self
,
attribute
)
->
Optional
[
Tuple
[
str
,
str
]]:
...
...
@@ -627,9 +629,7 @@ class EntitySchema(PermissionMixIn, ERSchema):
@
deprecation
.
argument_renamed
(
old_name
=
"skiprels"
,
new_name
=
"skip_relations"
)
def
is_subobject
(
self
,
strict
:
bool
=
False
,
skip_relations
:
Sequence
[
Tuple
[
Union
[
"RelationSchema"
,
str
],
str
]]
=
(),
self
,
strict
:
bool
=
False
,
skip_relations
:
Sequence
[
Tuple
[
"RelationSchema"
,
str
]]
=
(),
)
->
bool
:
"""return True if this entity type is contained by another. If strict,
return True if this entity type *must* be contained by another.
...
...
@@ -673,7 +673,7 @@ class EntitySchema(PermissionMixIn, ERSchema):
def
check
(
self
,
entity
:
Dict
[
Union
[
str
,
"RelationSchema"
]
,
Any
],
entity
:
Dict
[
"RelationSchema"
,
Any
],
creation
:
bool
=
False
,
_
=
None
,
relations
:
Optional
[
List
[
"RelationSchema"
]]
=
None
,
...
...
@@ -1020,8 +1020,8 @@ class RelationSchema(ERSchema):
self
.
_init_relation
(
relation_definition
)
# mapping to subject/object with schema as key
self
.
_subject_schemas
:
Dict
[
Any
,
List
]
=
{}
self
.
_object_schemas
:
Dict
[
Any
,
List
]
=
{}
self
.
_subject_schemas
:
Dict
[
"EntitySchema"
,
List
[
"EntitySchema"
]
]
=
{}
self
.
_object_schemas
:
Dict
[
"EntitySchema"
,
List
[
"EntitySchema"
]
]
=
{}
# relation properties
self
.
relation_definitions
:
Dict
[
...
...
@@ -1287,9 +1287,7 @@ class RelationSchema(ERSchema):
return
list
(
self
.
_subject_schemas
.
items
())
@
deprecation
.
argument_renamed
(
old_name
=
"etype"
,
new_name
=
"entity_type"
)
def
subjects
(
self
,
entity_type
:
Optional
[
Union
[
"EntitySchema"
,
str
]]
=
None
)
->
Tuple
[
"EntitySchema"
,
...]:
def
subjects
(
self
,
entity_type
:
Optional
[
"EntitySchema"
]
=
None
)
->
Tuple
[
"EntitySchema"
,
...]:
"""Return a list of entity schemas which can be subject of this relation.
If entity_type is not None, return a list of schemas which can be subject of
...
...
@@ -1306,9 +1304,7 @@ class RelationSchema(ERSchema):
raise
KeyError
(
f
"
{
self
}
does not have
{
entity_type
}
as object"
)
@
deprecation
.
argument_renamed
(
old_name
=
"etype"
,
new_name
=
"entity_type"
)
def
objects
(
self
,
entity_type
:
Optional
[
Union
[
"EntitySchema"
,
str
]]
=
None
)
->
Tuple
[
"EntitySchema"
,
...]:
def
objects
(
self
,
entity_type
:
Optional
[
"EntitySchema"
]
=
None
)
->
Tuple
[
"EntitySchema"
,
...]:
"""Return a list of entity schema which can be object of this relation.
If entity_type is not None, return a list of schemas which can be object of
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment