Skip to content

Align extra_slots support across pythongen/pydanticgen, per-class enabled#3630

Draft
noelmcloughlin wants to merge 1 commit into
linkml:mainfrom
noelmcloughlin:closed2
Draft

Align extra_slots support across pythongen/pydanticgen, per-class enabled#3630
noelmcloughlin wants to merge 1 commit into
linkml:mainfrom
noelmcloughlin:closed2

Conversation

@noelmcloughlin

@noelmcloughlin noelmcloughlin commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3629

  • Both generators read cls.extra_slots.allowed and emit per-class behavior that matches schema.

How was this tested?

Added unit tests

Areas of uncertainty

Checklist

  • My code follows the contributor guidelines
  • [x]I have added tests that prove my fix/feature works
  • Existing tests pass locally with my changes

AI Assistance

LLM assisted

@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.84%. Comparing base (195f07d) to head (def9729).

Files with missing lines Patch % Lines
packages/linkml/src/linkml/generators/pythongen.py 92.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3630      +/-   ##
==========================================
+ Coverage   80.43%   83.84%   +3.40%     
==========================================
  Files         158      158              
  Lines       19007    19037      +30     
  Branches     4004     4011       +7     
==========================================
+ Hits        15289    15961     +672     
+ Misses       2877     2187     -690     
- Partials      841      889      +48     
Flag Coverage Δ
linkml 80.44% <93.75%> (+0.02%) ⬆️
runtime 80.39% <93.75%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sneakers-the-rat

Copy link
Copy Markdown
Collaborator

On the pydanticgen part, there's a parallel conversation happening in a other PR re: json schema gen, and I think that the option for the generator to override the schema should be removed (previously it was not overriding the schema because there was no way to control extra slots in the schema).

Implementing extra slots also requires handling the expression form where a type is set for __pydantic_extra__. Should be simple to do with the existing methods and template objects, since the slot expression is the same type as all the others.

https://pydantic.dev/docs/validation/latest/concepts/models/#extra-data

@sneakers-the-rat

Copy link
Copy Markdown
Collaborator

I think the feature might be contained enough to do python and pydanticgen in one PR, but with the addition of handling the expression form, it might balloon a bit. If it becomes unwieldy, In general I would favor splitting it by generator rather than doing boolean form first and then expression form for both, just because I think we should ship the complete feature at a time. Might be worth doing that now and splitting PR before further work done, but up to you.

Re: the requested deprecation/pydanticgen part, I don't want to take work off your plate that youve already started, but I was planning on doing it this week anyway, and would be happy to help with that if its proving tricky. If you do the implementation, i can handle doing the deprecation notice for the generator param (unless you are interested in checking out how that works, at which point ofc explore!)

Just offering help if its wanted and a bit of guidance so it doesn't feel like I'm asking for huge changes without help, but again not trying to be overbearing or discouraging by taking it from you.

@noelmcloughlin noelmcloughlin marked this pull request as draft June 11, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent extra_slots support - Pythongen and Pydanticgen

2 participants