Skip to content

feat: make slurmutils compatible with python 3.14 - #72

Merged
NucciTheBoss merged 2 commits into
canonical:mainfrom
jedel1043:fix-python-3.14
Jul 14, 2026
Merged

feat: make slurmutils compatible with python 3.14#72
NucciTheBoss merged 2 commits into
canonical:mainfrom
jedel1043:fix-python-3.14

Conversation

@jedel1043

Copy link
Copy Markdown
Contributor

Pre-submission checklist

  • I read and followed the CONTRIBUTING guidelines.
  • I have ensured that lint, typecheck, and unit tests complete successfully.

Summary of changes

Between Python 3.12 and 3.14 there was a change on how annotation inspection works; you can still inspect annotations, but they're lazily resolved. As part of that, namespace["__annotations__"] was deleted in favour of annotationlib.get_annotation.
This PR adds a shim to address this breaking change while preserving compatibility with Python 3.10-3.12

Docs

  • I confirm that this pull request requires no changes or additions to documentation.

Internal change, doesn't require documentation.

@jedel1043
jedel1043 requested a review from a team as a code owner June 20, 2026 00:36
@jedel1043
jedel1043 requested review from NucciTheBoss and dsloanm and removed request for a team June 20, 2026 00:36
@jedel1043 jedel1043 added fix This pull request fixes a confirmed issue C-slurm Component: Slurm labels Jun 20, 2026

@NucciTheBoss NucciTheBoss left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We stan non-backward compatible changes in a minor version release with little to no deprecation warning :goberserk:

Couple of questions and suggestions around the implementation here. I think we need to make your comment more clear that __annotations__ is now lazily loaded rather than eagerly in Python 3.14 and above.

Also, this issue is making me realize that sooner rather than later we need to take a hard look at migrating the Slurm data models to pydantic in slurmutils v2. We rely heavily on how Python handles type annotations to provide additional metadata about Slurm configuration attributes, so further changes to how Python handles type hints/annotations in future releases may create even more headaches for us (also I feel like static typing is becoming more mainstream with LLM-assisted development).

Comment thread .github/workflows/ci.yaml Outdated
Comment thread src/slurmutils/core/base.py Outdated
Comment on lines +71 to +74
# `annotationlib` was added in Python 3.14 and replaces the old
# `__annotations__` property on all classes, so for backwards compat
# we provide a minimal shim mirroring the subset of the
# `annotationlib.get_annotations` that we use.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems misleading to me. To me it implies that the __annotations__ attribute was removed entirely from Python 3.14 when the real issue here is that we're relying on the old behavior of the __annotations__ attribute where it's computed eagerly, but Python 3.14 has changed to computing this value lazily.

The comment should be reworded to state something along the lines:

Suggested change
# `annotationlib` was added in Python 3.14 and replaces the old
# `__annotations__` property on all classes, so for backwards compat
# we provide a minimal shim mirroring the subset of the
# `annotationlib.get_annotations` that we use.
# Python < 3.14 computed the `__annotations__` attribute eagerly, but Python >= 3.14 now
# computes the value of this attribute lazily. PEP 749 encourages explicitly using the
# `get_annotations` function from the `annotationlib` module to compute the
# annotation dictionary rather than read the lazily-loaded `__annotations__` attribute.
# `annotationlib` was added in Python 3.14, so for backwards compatibility we need to create
# this minimal shim that mirrors the functionality of the `get_annotations` for Python < 3.14.

@jedel1043 jedel1043 Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace["__annotations__"] was removed and replaced by the get_annotations API, but the new get_annotations API also brought the additional change in behaviour. Though now that I read my comment, it does read very weirdly so I'll adjust it.

Scratch that, I double checked and yeah, thought __annotations__ was deleted but it's just computed lazily now

Scratch the scratch, my comment wasn't precise enough. __annotations__ was deleted from the namespace argument of ABCMeta classes, but it is still available on normal classes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded the comment in 0e3d6cd

Comment thread src/slurmutils/core/base.py Outdated
Comment thread src/slurmutils/core/base.py
@jedel1043

Copy link
Copy Markdown
Contributor Author

Also, this issue is making me realize that sooner rather than later we need to take a hard look at migrating the Slurm data models to pydantic in slurmutils v2. We rely heavily on how Python handles type annotations to provide additional metadata about Slurm configuration attributes, so further changes to how Python handles type hints/annotations in future releases may create even more headaches for us (also I feel like static typing is becoming more mainstream with LLM-assisted development).

Yes, the code is filled with very advanced Python snippets that might not be as easy to maintain in the long run. If we can migrate to pydantic ASAP I would be very happy

@jedel1043
jedel1043 requested a review from NucciTheBoss June 24, 2026 17:59

@NucciTheBoss NucciTheBoss left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last qualm and then I'm good to merge this PR.

I think we need to be more explicit about __annotations__ now being lazily evaluated in Python 3.14+, and that we're primarily introducing get_annotations with a shim for Python < 3.14 so that we can safely access annotations across all versions.

Comment thread src/slurmutils/core/base.py Outdated
@jedel1043
jedel1043 requested a review from a team as a code owner July 14, 2026 21:26
@jedel1043
jedel1043 requested review from NucciTheBoss and removed request for a team July 14, 2026 21:26
Co-authored-by: Jason Nucciarone <40342202+NucciTheBoss@users.noreply.github.com>

@NucciTheBoss NucciTheBoss left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! :shipit:

Can you run uv version --bump minor to update the version of slurmutils? Once you do that, I can merge the PR and our GitHub Actions automation will automatically handle tagging and publishing a new release to PyPI.

@jedel1043

Copy link
Copy Markdown
Contributor Author

@NucciTheBoss Done! Should be ready for publishing now

@NucciTheBoss

Copy link
Copy Markdown
Collaborator

@NucciTheBoss Done! Should be ready for publishing now

Thanks bro 🦀

@NucciTheBoss
NucciTheBoss merged commit cd5badc into canonical:main Jul 14, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-slurm Component: Slurm fix This pull request fixes a confirmed issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants