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
727b5e6d9f13
Commit
25d31f47
authored
May 07, 2020
by
Laurent Peuch
Browse files
[rename] all those entity_type are actually entity_schema
parent
649e6df93853
Pipeline
#9454
passed with stages
in 6 minutes and 12 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
yams/schema.py
View file @
727b5e6d
...
...
@@ -1286,49 +1286,51 @@ class RelationSchema(ERSchema):
# XXX deprecates in favor of iter_relation_definitions() ?
return
list
(
self
.
_subject_schemas
.
items
())
@
deprecation
.
argument_renamed
(
old_name
=
"etype"
,
new_name
=
"entity_type"
)
def
subjects
(
self
,
entity_type
:
Optional
[
"EntitySchema"
]
=
None
)
->
Tuple
[
"EntitySchema"
,
...]:
@
deprecation
.
argument_renamed
(
old_name
=
"etype"
,
new_name
=
"entity_schema"
)
def
subjects
(
self
,
entity_schema
:
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
this relation with entity_
type
as object.
If entity_
schema
is not None, return a list of schemas which can be subject of
this relation with entity_
schema
as object.
:raise `KeyError`: if entity_
type
is not a subject entity type.
:raise `KeyError`: if entity_
schema
is not a subject entity type.
"""
if
entity_
type
is
None
:
if
entity_
schema
is
None
:
return
tuple
(
self
.
_subject_schemas
)
if
entity_
type
in
self
.
_object_schemas
:
return
tuple
(
self
.
_object_schemas
[
entity_
type
])
if
entity_
schema
in
self
.
_object_schemas
:
return
tuple
(
self
.
_object_schemas
[
entity_
schema
])
else
:
raise
KeyError
(
f
"
{
self
}
does not have
{
entity_
type
}
as object"
)
raise
KeyError
(
f
"
{
self
}
does not have
{
entity_
schema
}
as object"
)
@
deprecation
.
argument_renamed
(
old_name
=
"etype"
,
new_name
=
"entity_
type
"
)
def
objects
(
self
,
entity_
type
:
Optional
[
"EntitySchema"
]
=
None
)
->
Tuple
[
"EntitySchema"
,
...]:
@
deprecation
.
argument_renamed
(
old_name
=
"etype"
,
new_name
=
"entity_
schema
"
)
def
objects
(
self
,
entity_
schema
:
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
this relation with entity_
type
as subject.
If entity_
schema
is not None, return a list of schemas which can be object of
this relation with entity_
schema
as subject.
:raise `KeyError`: if entity_
type
is not an object entity type.
:raise `KeyError`: if entity_
schema
is not an object entity type.
"""
if
entity_
type
is
None
:
if
entity_
schema
is
None
:
return
tuple
(
self
.
_object_schemas
)
try
:
return
tuple
(
self
.
_subject_schemas
[
entity_
type
])
return
tuple
(
self
.
_subject_schemas
[
entity_
schema
])
except
KeyError
:
raise
KeyError
(
f
"
{
self
}
does not have
{
entity_
type
}
as subject"
)
raise
KeyError
(
f
"
{
self
}
does not have
{
entity_
schema
}
as subject"
)
@
deprecation
.
argument_renamed
(
old_name
=
"etype"
,
new_name
=
"entity_
type
"
)
@
deprecation
.
argument_renamed
(
old_name
=
"etype"
,
new_name
=
"entity_
schema
"
)
def
targets
(
self
,
entity_
type
:
Optional
[
"EntitySchema"
]
=
None
,
role
:
str
=
"subject"
self
,
entity_
schema
:
Optional
[
"EntitySchema"
]
=
None
,
role
:
str
=
"subject"
)
->
Tuple
[
"EntitySchema"
,
...]:
"""return possible target types with <entity_
type
> as <x>"""
"""return possible target types with <entity_
schema
> as <x>"""
if
role
==
"subject"
:
return
self
.
objects
(
entity_
type
)
return
self
.
objects
(
entity_
schema
)
return
self
.
subjects
(
entity_
type
)
return
self
.
subjects
(
entity_
schema
)
def
relation_definition
(
self
,
subject
:
yams_types
.
DefinitionName
,
object
:
yams_types
.
DefinitionName
...
...
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