-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: rename declare_static() to derive(), deprecate old name #24
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
Merged
ErnestM1234
merged 3 commits into
generaltranslation:main
from
moss-bryophyta:e/derive-rename
Mar 18, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| pypi/generaltranslation: minor | ||
| pypi/gt-i18n: minor | ||
| pypi/gt-fastapi: minor | ||
| pypi/gt-flask: minor | ||
| --- | ||
|
|
||
| refactor: rename `declare_static()` to `derive()` and deprecate `declare_static()` |
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
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
9 changes: 0 additions & 9 deletions
9
packages/generaltranslation/src/generaltranslation/static/_declare_static.py
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
packages/generaltranslation/src/generaltranslation/static/_derive.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import warnings | ||
|
|
||
|
|
||
| def derive(content: object) -> object: | ||
| """Mark *content* as derivable (statically analyzable). | ||
|
|
||
| This is an identity function used as a marker for the CLI tool's | ||
| static analysis. | ||
| """ | ||
| return content | ||
|
|
||
|
|
||
| def declare_static(content: object) -> object: | ||
| """Mark *content* as derivable (statically analyzable). | ||
|
|
||
| .. deprecated:: | ||
| Use :func:`derive` instead. | ||
|
ErnestM1234 marked this conversation as resolved.
|
||
| """ | ||
| warnings.warn( | ||
| "declare_static() is deprecated, use derive() instead.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| return derive(content) | ||
24 changes: 24 additions & 0 deletions
24
packages/generaltranslation/tests/static/test_declare_static.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| """Tests for the deprecated declare_static() function.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import warnings | ||
|
|
||
| from generaltranslation import declare_static | ||
|
|
||
|
|
||
| class TestDeclareStaticDeprecation: | ||
| """Placeholder tests for declare_static() — deprecated in favour of derive().""" | ||
|
|
||
| def test_emits_deprecation_warning(self) -> None: | ||
| with warnings.catch_warnings(record=True) as w: | ||
| warnings.simplefilter("always") | ||
| declare_static("hello") | ||
| assert len(w) == 1 | ||
| assert issubclass(w[0].category, DeprecationWarning) | ||
| assert "derive()" in str(w[0].message) | ||
|
|
||
| def test_still_returns_value(self) -> None: | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter("ignore", DeprecationWarning) | ||
| assert declare_static("hello") == "hello" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """Tests for the derive() function.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from generaltranslation import derive | ||
|
|
||
|
|
||
| class TestDerive: | ||
| """Tests for derive() — the canonical marker for derivable content.""" | ||
|
|
||
| def test_returns_same_string(self) -> None: | ||
| assert derive("hello") == "hello" | ||
|
|
||
| def test_returns_same_int(self) -> None: | ||
| assert derive(42) == 42 | ||
|
|
||
| def test_returns_same_float(self) -> None: | ||
| assert derive(3.14) == 3.14 | ||
|
|
||
| def test_returns_same_list(self) -> None: | ||
| value = [1, 2, 3] | ||
| assert derive(value) is value | ||
|
|
||
| def test_returns_same_dict(self) -> None: | ||
| value = {"key": "value"} | ||
| assert derive(value) is value | ||
|
|
||
| def test_returns_none(self) -> None: | ||
| assert derive(None) is None | ||
|
|
||
| def test_returns_same_bool(self) -> None: | ||
| assert derive(True) is True | ||
|
|
||
| def test_identity_preserves_reference(self) -> None: | ||
| """derive() should be a pure identity function — same object in, same object out.""" | ||
| obj = object() | ||
| assert derive(obj) is obj | ||
|
|
||
| def test_nested_structure(self) -> None: | ||
| value = {"a": [1, {"b": 2}]} | ||
| assert derive(value) is value | ||
|
|
||
| def test_empty_string(self) -> None: | ||
| assert derive("") == "" | ||
|
|
||
| def test_multiline_string(self) -> None: | ||
| text = "line one\nline two\nline three" | ||
| assert derive(text) == text |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.