Python reserved keyword 'class' blocking Weave installation#1
Merged
zbirenbaum merged 1 commit intozbirenbaum:masterfrom Nov 20, 2025
Merged
Conversation
Problem: Kaitai Struct compiler generates code using 'class' as a variable name, causing SyntaxError on import. This affects openpgp_message.py lines 361, 369-371. Solution: Added automatic patching in polyfile/__init__.py that: - Detects if openpgp_message.py uses the reserved keyword - Automatically replaces self.class with self.class_ before module imports - Runs silently without breaking imports if any issues occur - Ensures the package works out-of-the-box without manual intervention Changes made: - polyfile/__init__.py: Added _fix_class_keyword_if_needed() auto-fix function - polyfile/kaitai/parsers/openpgp_message.py: Auto-fixed by the import hook - fix_class_keyword.py: Standalone script for manual fixing if needed - .gitignore: Added *.egg-info/ to ignore build artifacts Tested and verified: The auto-fix successfully patches the file on first import. Fixes import errors in polyfile-weave v0.1.6 and earlier.
Owner
|
Thanks for this! sorry I seem to have missed the notification |
zbirenbaum
pushed a commit
that referenced
this pull request
Jan 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This bug prevents the installation and usage of Weights & Biases Weave in python 3.9 where compiling happens at install because polyfile-weave is a dependency of Weave. When Weave tries to import polyfile, it fails with a
SyntaxError, making Weave completely unusable.How This Was Discovered
While trying to use Weave for ML experiment tracking, we encountered:
This import error cascades up and prevents Weave from functioning.
The Problem
The Kaitai Struct compiler generates invalid Python code in
polyfile/kaitai/parsers/openpgp_message.py. It usesself.class = ...which causes aSyntaxErrorbecauseclassis a reserved keyword in Python (since Python 1.0).Impact
Solution
This PR adds automatic patching that fixes the issue transparently on import, ensuring both polyfile-weave and its dependents (like Weave) work out-of-the-box.
Changes Made
polyfile/__init__.py: Added_fix_class_keyword_if_needed()function that:openpgp_message.pyuses the reserved keywordclassself.classwithself.class_before module importspolyfile/kaitai/parsers/openpgp_message.py: Auto-fixed by the import hook:self.class→self.class_SEQ_FIELDS = ["class"...]→SEQ_FIELDS = ["class_"...]['class']→['class_']fix_class_keyword.py: Standalone script for manual fixing if neededREADME.md: Updated with Known Issues section.gitignore: Added*.egg-info/to ignore build artifactsTesting
The fix has been tested and successfully:
Verification
Related Fixes
Note
This is a workaround for a bug in the Kaitai Struct compiler. Once the compiler is fixed upstream and new parsers are generated, this auto-fix will no longer be necessary but will remain harmless if left in place.