Skip to content
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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

candleindark
Copy link
Contributor

@candleindark candleindark commented Aug 27, 2024

This PR does the following.

  1. Prevent the use of kwargs in setting the class to be added with an unacceptable attribute if cls is given as a ClassDefinition object (test provided)
  2. Correct detection of duplicating classes. (test provided)
  3. Handle the case slots is None while use_attributes is True (test provided)
  4. Update the example in the doc string of SchemaBuilder to have the correct import statement (no test needed)
  5. Provide documentation of the use_attributes param in the docstring (no test needed)
  6. Give more informative documentation for the slot_usage param according to the behavior of existing code. (no test needed)
  7. Provide type annotation to the replace_if_present and use_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 a dict or str and are inconsistent with the behavior of SchemaBuilder.add_slot() and SchemaBuilder.add_enum(). In both SchemaBuilder.add_slot() and SchemaBuilder.add_enum(), if the first argument is of the target type, SlotDefinition and EnumDefinition respectively, kwargs is ignored.

for k, v in kwargs.items():
setattr(cls, k, v)

- 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`
@candleindark candleindark marked this pull request as ready for review August 27, 2024 01:00
@yarikoptic
Copy link

If you could add a test which would demonstrate (fail) the issue without this fix, that would be great.

Copy link
Member

@cmungall cmungall left a 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?

@candleindark
Copy link
Contributor Author

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.

@cmungall
Copy link
Member

cmungall commented Sep 5, 2024

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
@candleindark
Copy link
Contributor Author

@cmungall Tests are provided for the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants