|
1 | 1 | # Copyright (c) QuantCo 2025-2025 |
2 | 2 | # SPDX-License-Identifier: BSD-3-Clause |
3 | 3 |
|
| 4 | +import sys |
| 5 | + |
4 | 6 | import polars as pl |
5 | 7 | import pytest |
6 | 8 | from polars.testing import assert_frame_equal |
@@ -110,3 +112,37 @@ def test_collect_all_optional() -> None: |
110 | 112 | assert isinstance(out, MyCollection) |
111 | 113 | assert len(out.first.collect()) == 3 |
112 | 114 | assert out.second is None |
| 115 | + |
| 116 | + |
| 117 | +@pytest.mark.skipif(sys.version_info < (3, 14), reason="Python 3.14+ only") |
| 118 | +def test_annotate_func_none_py314() -> None: |
| 119 | + """Test that __annotate_func__ = None doesn't cause TypeError in Python 3.14. |
| 120 | +
|
| 121 | + In Python 3.14 with PEP 649, __annotate_func__ can be None when: |
| 122 | + - A class has no annotations |
| 123 | + - Annotations are being processed during certain import contexts |
| 124 | + - Classes are created dynamically with __annotate_func__ set to None |
| 125 | +
|
| 126 | + This test ensures the metaclass handles this gracefully. |
| 127 | + """ |
| 128 | + from typing import cast |
| 129 | + |
| 130 | + from dataframely.collection._base import BaseCollection, CollectionMeta |
| 131 | + |
| 132 | + # Create a namespace with __annotate_func__ = None |
| 133 | + namespace = { |
| 134 | + "__module__": "__main__", |
| 135 | + "__qualname__": "TestCollection", |
| 136 | + "__annotate_func__": None, |
| 137 | + } |
| 138 | + |
| 139 | + # This should not raise TypeError |
| 140 | + TestCollection = CollectionMeta( |
| 141 | + "TestCollection", |
| 142 | + (dy.Collection,), |
| 143 | + namespace, |
| 144 | + ) |
| 145 | + |
| 146 | + # Verify it has no members (since there are no annotations) |
| 147 | + # Cast to BaseCollection to satisfy mypy since CollectionMeta creates Collection classes |
| 148 | + assert cast(type[BaseCollection], TestCollection).members() == {} |
0 commit comments