Skip to content

Commit

Permalink
Fix test for python < 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine DECHAUME committed Nov 24, 2022
1 parent e50d779 commit ccdf57e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pydantic_numpy/ndarray.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from abc import ABC, abstractmethod
from typing import Any, Generic, Mapping, Optional, Type, TypeVar
import sys

import numpy as np
from numpy.lib import NumpyVersion
from pydantic import BaseModel, FilePath, validator
from pydantic.fields import ModelField

T = TypeVar("T", bound=np.generic)
nd_array_type = np.ndarray if NumpyVersion(np.__version__) < "1.22.0" else np.ndarray[Any, T]

if sys.version_info < (3, 9) or NumpyVersion(np.__version__) < "1.22.0":
nd_array_type = np.ndarray
else:
nd_array_type = np.ndarray[Any, T]


class NPFileDesc(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ndarray.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
from typing import Optional
from typing import Dict

import numpy as np
import pytest
Expand Down Expand Up @@ -131,7 +132,7 @@ def test_subclass_basemodel():
assert model_field.json()

class MappingTestingModel(BaseModel):
L: dict[str, NDArrayTestingModel]
L: Dict[str, NDArrayTestingModel]

class Config:
json_encoders = JSON_ENCODERS
Expand Down

0 comments on commit ccdf57e

Please sign in to comment.