refactor: rename declare_static() to derive(), deprecate old name#24
Merged
ErnestM1234 merged 3 commits intogeneraltranslation:mainfrom Mar 18, 2026
Merged
Conversation
Mirrors the JS/TS rename from generaltranslation/gt#1062. - Add derive() as the primary function in _derive.py - declare_static() is now a deprecated wrapper that emits a DeprecationWarning - All packages (generaltranslation, gt-i18n, gt-flask, gt-fastapi) export both names - No breaking changes: existing code using declare_static() continues to work
Contributor
|
@greptileai plz review |
ErnestM1234
approved these changes
Mar 18, 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.
Mirrors generaltranslation/gt#1062 for the Python libraries.
Changes
derive()function as the canonical replacement fordeclare_static()declare_static()now delegates toderive()and emits aDeprecationWarningderivefrom all packages:generaltranslation,gt-i18n,gt-fastapi,gt-flaskGreptile Summary
This PR introduces
derive()as the new canonical replacement fordeclare_static()across all four packages (generaltranslation,gt-i18n,gt-fastapi,gt-flask), mirroring a parallel change in the JS/TS libraries.declare_static()is preserved as a deprecated wrapper that delegates toderive()and emits aDeprecationWarning, ensuring backwards compatibility.Key changes:
_derive.pyreplaces the deleted_declare_static.py, housing bothderive()(canonical) anddeclare_static()(deprecated shim withstacklevel=2correctly set)deriveexported from all public package__all__lists consistentlytest_derive.pycovers identity semantics across all common Python types;test_declare_static.pyverifies the deprecation warning and passthrough behaviour# Staticto# Derive / variable helpersacross package__init__.pyfilesMinor observations:
declare_staticdocstring's first line duplicatesderive()'s summary without flagging the deprecation upfront — worth clarifying for API reference readersassert len(w) == 1assertion intest_emits_deprecation_warningis slightly brittle; using a predicate-based check would be more robust against future incidental warningsConfidence Score: 5/5
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["User code calls\ndeclare_static(content)"] -->|deprecated path| B["declare_static()\nin _derive.py"] B --> C["warnings.warn(DeprecationWarning,\nstacklevel=2)"] C --> D["derive(content)"] E["User code calls\nderive(content)"] -->|canonical path| D D --> F["return content\n(identity function)"] subgraph Packages ["Re-exported from all packages"] G[generaltranslation] H[gt-i18n] I[gt-fastapi] J[gt-flask] end D -.->|exported via| G D -.->|exported via| H D -.->|exported via| I D -.->|exported via| JComments Outside Diff (1)
packages/generaltranslation/src/generaltranslation/__init__.py, line 51-58 (link)deriveimport breaks alphabetical orderingThe existing import block appears to be sorted alphabetically (
condense_vars,declare_static,declare_var,decode_vars, …). Insertingderivebetweendeclare_varanddecode_varsbreaks that order — alphabeticallydecode_vars(deco…) should precedederive(deri…).Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix All With AI
Last reviewed commit: "chore: add changeset..."