-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BF: Fix bug and other improvement in SchemaBuilder.add_class()
#338
base: main
Are you sure you want to change the base?
Conversation
- Remove use of `kwargs` in setting `cls` if it's given as `ClassDefinition` - Correct detection of duplicating classes - Ensure `slots` is correct type when `use_attributes=True`
If you could add a test which would demonstrate (fail) the issue without this fix, that would be great. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @candleindark - do you think you can add the test as @yarikoptic suggests?
I think I can do that. Any suggestion in where is the best place to put these tests. |
Hmm, I thought we had a test_schemabuilder here https://github.com/linkml/linkml-runtime/tree/main/tests/test_utils but it seems not... if you can start one that would be great. We favor simple pytest style tests. |
The example is outdated since `SchemaBuilder` no longer resides in `linkml.utils.schema_builder`
In this way, the slot definition in `slots` can be added to the class as an attribute, better than raising an exception
9cc06b2
to
e2256f1
Compare
The bundling is actually not needed. The type annotation of `slots` already ensures that it is a list or `None`
Test the case of adding a class with a name that is the same as a class that already exists in the schema
… dict This can simplify the code
…tion` This time with detection of unsupported fields provided by `kwargs`
@cmungall Tests are provided for the changes. |
This PR does the following.
kwargs
in setting the class to be added with an unacceptable attribute ifcls
is given as aClassDefinition
object (test provided)slots
isNone
whileuse_attributes
isTrue
(test provided)SchemaBuilder
to have the correct import statement (no test needed)use_attributes
param in the docstring (no test needed)slot_usage
param according to the behavior of existing code. (no test needed)replace_if_present
anduse_attributes
params (no test needed)Point 1 is included in this PR because the following lines are unneeded for the cases in which
cls
is given as adict
orstr
and are inconsistent with the behavior ofSchemaBuilder.add_slot()
andSchemaBuilder.add_enum()
. In bothSchemaBuilder.add_slot()
andSchemaBuilder.add_enum()
, if the first argument is of the target type,SlotDefinition
andEnumDefinition
respectively,kwargs
is ignored.linkml-runtime/linkml_runtime/utils/schema_builder.py
Lines 101 to 102 in 9fd5a3e