Skip to content

Commit

Permalink
Support Pydantic v2 (#364)
Browse files Browse the repository at this point in the history
* Bump up mypy version to 1.0.1

* Import from Pydantic conditioned on whether it has `v1`

* Bump up Pydantic dev version to 2.3.0
  • Loading branch information
Nour-Mws authored Sep 12, 2023
1 parent b45988f commit d2c8204
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 86 deletions.
5 changes: 4 additions & 1 deletion fawltydeps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
from operator import attrgetter
from typing import Dict, Iterator, List, Optional, Set, TextIO, Type

from pydantic.json import custom_pydantic_encoder # pylint: disable=no-name-in-module
try: # import from Pydantic V2
from pydantic.v1.json import custom_pydantic_encoder
except ModuleNotFoundError:
from pydantic.json import custom_pydantic_encoder # type: ignore[no-redef]

from fawltydeps import extract_declared_dependencies, extract_imports
from fawltydeps.check import calculate_undeclared, calculate_unused
Expand Down
13 changes: 9 additions & 4 deletions fawltydeps/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
from pathlib import Path
from typing import ClassVar, List, Optional, Set, TextIO, Tuple, Type, Union

from pydantic import BaseSettings
from pydantic.env_settings import SettingsSourceCallable # pylint: disable=E0611
from pydantic.json import custom_pydantic_encoder # pylint: disable=no-name-in-module
try: # import from Pydantic V2
from pydantic.v1 import BaseSettings
from pydantic.v1.env_settings import SettingsSourceCallable
from pydantic.v1.json import custom_pydantic_encoder
except ModuleNotFoundError:
from pydantic import BaseSettings # type: ignore[no-redef]
from pydantic.env_settings import SettingsSourceCallable # type: ignore[no-redef]
from pydantic.json import custom_pydantic_encoder # type: ignore[no-redef]

from fawltydeps.types import CustomMapping, ParserChoice, PathOrSpecial, TomlData

Expand Down Expand Up @@ -93,7 +98,7 @@ def parse_path_or_stdin(arg: str) -> PathOrSpecial:
return Path(arg)


class Settings(BaseSettings): # type: ignore
class Settings(BaseSettings):
"""FawltyDeps settings.
Below, you find the defaults, these can be overridden in multiple ways:
Expand Down
Loading

0 comments on commit d2c8204

Please sign in to comment.