Skip to content

Commit b463bdb

Browse files
committed
fix: Remove pydantic.v1 warning for Python 3.14
When running in Python 3.14, importing pydantic.v1 produces a warning message. The code was porting it specifically for a Python 3.9 compatibility issue, so this change is to only do that import in Python 3.9 and for 3.10+ only use the newer pydantic. Added Python versions 3.13 and 3.14 to the github action test matrix Signed-off-by: Mark <399551+mwiebe@users.noreply.github.com>
1 parent 7f96697 commit b463bdb

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

.github/workflows/code_quality.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
matrix:
2020
os: [ubuntu-latest, windows-latest, macos-latest]
21-
python-version: ['3.9', '3.10', '3.11', '3.12']
21+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
2222
uses: OpenJobDescription/.github/.github/workflows/reusable_python_build.yml@mainline
2323
with:
2424
os: ${{ matrix.os }}

src/openjd/model/_internal/_variable_reference_validation.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22

3+
import sys
34
from collections import defaultdict
45
import typing
56
from typing import cast, Any, Optional, Type, Literal, Union
@@ -9,8 +10,11 @@
910
from pydantic_core import InitErrorDetails
1011
from pydantic.fields import FieldInfo, ModelPrivateAttr
1112

12-
# Workaround for Python 3.9 where issubclass raises an error "TypeError: issubclass() arg 1 must be a class"
13-
from pydantic.v1.utils import lenient_issubclass
13+
if sys.version_info >= (3, 10):
14+
_issubclass_for_pydantic = issubclass
15+
else:
16+
# Workaround for Python 3.9 where issubclass raises an error "TypeError: issubclass() arg 1 must be a class"
17+
from pydantic.v1.utils import lenient_issubclass as _issubclass_for_pydantic
1418

1519
from .._types import OpenJDModel, ResolutionScope, ModelParsingContextInterface
1620
from .._format_strings import FormatString, FormatStringError
@@ -307,7 +311,7 @@ def _validate_model_template_variable_references(
307311
else:
308312
return errors
309313

310-
if isclass(model) and lenient_issubclass(model, FormatString):
314+
if isclass(model) and _issubclass_for_pydantic(model, FormatString):
311315
if not isinstance(value, FormatString):
312316
if context is None:
313317
raise ValueError(
@@ -321,7 +325,9 @@ def _validate_model_template_variable_references(
321325
return _check_format_string(value, current_scope, symbols, loc, context=context)
322326

323327
# Return an empty error list if it's not an OpenJDModel, or if it's not a dict
324-
if not (isclass(model) and lenient_issubclass(model, OpenJDModel) and isinstance(value, dict)):
328+
if not (
329+
isclass(model) and _issubclass_for_pydantic(model, OpenJDModel) and isinstance(value, dict)
330+
):
325331
return []
326332

327333
# Does this cls change the variable reference scope for itself and its children? If so, then update
@@ -557,7 +563,7 @@ def _collect_variable_definitions( # noqa: C901 (suppress: too complex)
557563
return {"__export__": ScopedSymtabs()}
558564

559565
# Anything except for an OpenJDModel returns an empty result
560-
if not isclass(model) or not lenient_issubclass(model, OpenJDModel):
566+
if not isclass(model) or not _issubclass_for_pydantic(model, OpenJDModel):
561567
return {"__export__": ScopedSymtabs()}
562568

563569
# If the model has no exported variable definitions, prune it

0 commit comments

Comments
 (0)