Skip to content

Commit 905789c

Browse files
authored
Merge pull request #384 from linkml/restore-dataclass_extensions_376
restore dataclass_extensions. See #345
2 parents a1db174 + 8f4ede4 commit 905789c

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

.github/workflows/test-upstream.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ jobs:
118118
python-version: ${{ matrix.python-version }}
119119

120120
- name: Install poetry
121-
run: pipx install poetry
121+
run: pipx install poetry==1.*
122+
123+
- name: Check Poetry version
124+
run: poetry --version
122125

123126
- name: Install dynamic versioning plugin
124127
run: poetry self add "poetry-dynamic-versioning[plugin]"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![PyPIDownloadsMonth](https://img.shields.io/pypi/dm/linkml-runtime?logo=PyPI&color=blue)](https://pypi.org/project/linkml-runtime)
88
[![codecov](https://codecov.io/gh/linkml/linkml-runtime/branch/main/graph/badge.svg?token=FOBHNSK5WG)](https://codecov.io/gh/linkml/linkml-runtime)
99

10-
Runtime support for linkml generated data classes
10+
Runtime support for linkml generated data classes.
1111

1212
## About
1313

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import sys
2+
import warnings
3+
import dataclasses
4+
5+
warnings.warn(
6+
"The LinkML dataclass extension patch is deprecated and will be removed in a future release.\n"
7+
"If you're currently using Python < 3.13, where this patch still applies, you should:\n"
8+
" • Upgrade your LinkML tooling to version >= 1.9.0 (which no longer needs this patch), OR\n"
9+
" • Migrate to Pydantic models if you're using LinkML's generated classes at runtime.\n",
10+
DeprecationWarning,
11+
stacklevel=2
12+
)
13+
14+
dataclasses_init_fn_with_kwargs = dataclasses._init_fn
15+
DC_CREATE_FN = False
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
import pytest
3+
import importlib.util
4+
import dataclasses
5+
6+
7+
def import_patch_module():
8+
"""Fresh import to ensure warning is triggered"""
9+
spec = importlib.util.find_spec("linkml_runtime.utils.dataclass_extensions_376")
10+
mod = importlib.util.module_from_spec(spec)
11+
spec.loader.exec_module(mod)
12+
return mod
13+
14+
def test_patch_module_emits_deprecation_warning():
15+
"""All Python versions: emits DeprecationWarning and defines compatibility symbols"""
16+
with pytest.warns(DeprecationWarning):
17+
mod = import_patch_module()
18+
19+
assert hasattr(mod, "DC_CREATE_FN")
20+
assert hasattr(mod, "dataclasses_init_fn_with_kwargs")
21+
assert mod.DC_CREATE_FN is False
22+
23+
# Check consistency with actual dataclasses module
24+
init_fn = getattr(dataclasses, "_init_fn", None)
25+
assert mod.dataclasses_init_fn_with_kwargs == init_fn
26+
27+

0 commit comments

Comments
 (0)