Skip to content

Commit

Permalink
chore: enable pydantic mypy plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Panos Vagenas <[email protected]>
  • Loading branch information
vagenas committed Sep 1, 2023
1 parent 00c77f8 commit 2360254
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 21 deletions.
3 changes: 1 addition & 2 deletions deepsearch/core/cli/profile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Optional

import typer
from pydantic import SecretStr
from rich.console import Console
from rich.table import Table
from typing_extensions import Annotated
Expand Down Expand Up @@ -43,7 +42,7 @@ def add_profile(
profile_settings = ProfileSettings(
host=host,
username=username,
api_key=SecretStr(api_key),
api_key=api_key,
verify_ssl=verify_ssl,
)

Expand Down
6 changes: 2 additions & 4 deletions deepsearch/core/client/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ def from_cli_prompt(cls) -> ProfileSettings:
return cls(
host=input("Host: "),
username=input("Username: "),
api_key=SecretStr(getpass("API key: ")),
verify_ssl=True
if input("SSL verification [y/n]: ") == "y" or "Y"
else False,
api_key=getpass("API key: "),
verify_ssl=input("SSL verification [y/n]: "),
)


Expand Down
9 changes: 6 additions & 3 deletions deepsearch/core/client/settings_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Dict, Optional

import platformdirs
from pydantic import SecretStr, ValidationError
from pydantic import ValidationError

from deepsearch.core.cli.profile_utils import (
MSG_AMBIGUOUS_SUCCESSOR,
Expand Down Expand Up @@ -40,6 +40,8 @@ def __init__(self) -> None:
)
self._main_path = self.config_root_path / MAIN_DOTENV_FILENAME
self._main_settings = MainSettings(_env_file=self._main_path) # type: ignore
# suppressing due to known Pydantic bug https://github.com/pydantic/pydantic/issues/3072

self._profile_root_path = self.config_root_path / PROFILES_DIR_NAME
self._profile_root_path.mkdir(exist_ok=True)

Expand All @@ -52,6 +54,7 @@ def __init__(self) -> None:
self._profile_cache[profile_name] = ProfileSettingsEntry(
path=file_path,
settings=ProfileSettings(_env_file=file_path), # type: ignore
# suppressing due to known Pydantic bug https://github.com/pydantic/pydantic/issues/3072
)

# reset any stale active profile config
Expand Down Expand Up @@ -85,7 +88,7 @@ def _migrate_legacy_config(self) -> None:
new_cfg = ProfileSettings(
host=legacy_cfg.host,
username=legacy_cfg.auth.username,
api_key=SecretStr(legacy_cfg.auth.api_key),
api_key=legacy_cfg.auth.api_key,
verify_ssl=legacy_cfg.verify_ssl,
)
self.save_settings(
Expand Down Expand Up @@ -113,7 +116,7 @@ def get_profile_settings(
prfl_name = profile_name or self.get_active_profile()
if prfl_name is None:
try: # try to instantiate from environment alone
return ProfileSettings() # type: ignore
return ProfileSettings()
except ValidationError:
if len(self._profile_cache) == 0:
raise RuntimeError(MSG_NO_PROFILES_DEFINED)
Expand Down
4 changes: 2 additions & 2 deletions deepsearch/documents/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class ConversionSettings(BaseModel):

@classmethod
def from_project(cls, api: CpsApi, proj_key: str) -> "ConversionSettings":
conv_settings = cls() # type: ignore
conv_settings = cls()

proj_key, _ = get_ccs_project_key(api, proj_key)

Expand All @@ -372,7 +372,7 @@ def from_project(cls, api: CpsApi, proj_key: str) -> "ConversionSettings":

@classmethod
def from_defaults(cls, api: CpsApi) -> "ConversionSettings":
conv_settings = cls() # type: ignore
conv_settings = cls()

request_conv_settings = api.client.session.get(
url=URLNavigator(api).url_conversion_defaults()
Expand Down
3 changes: 1 addition & 2 deletions deepsearch/model/examples/dummy_nlp_annotator/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
AnnotationLabels,
EntityLabel,
NLPConfig,
NLPType,
)


Expand All @@ -24,7 +23,7 @@ def __init__(self) -> None:
kind=Kind.NLPModel,
name="DummyNLPAnnotator",
version="0.1.0",
supported_types=[NLPType("text")],
supported_types=["text"],
labels=self._generate_labels(),
)

Expand Down
8 changes: 3 additions & 5 deletions deepsearch/model/kinds/nlp/controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Literal

from fastapi import HTTPException, status

from deepsearch.model.base.controller import BaseController
Expand Down Expand Up @@ -31,11 +29,11 @@ def __init__(self, model: BaseNLPModel):
def get_info(self) -> NLPInfoOutput:
cfg = self._model.get_nlp_config()
metadata = NLPModelMetadata(
supported_object_types=cfg.supported_types, # type: ignore
supported_object_types=cfg.supported_types,
**self._get_metadata().dict(), # passing parent metadata dict as kwargs
)
spec = NLPInfoOutputDefinitionsSpec(
definition=cfg.labels.dict(),
definition=cfg.labels,
metadata=metadata,
)
definitions = NLPInfoOutputDefinitions(
Expand All @@ -45,7 +43,7 @@ def get_info(self) -> NLPInfoOutput:
)
return NLPInfoOutput(definitions=definitions)

def get_kind(self) -> Literal[Kind.NLPModel]:
def get_kind(self) -> str:
return Kind.NLPModel

def _get_model(self) -> BaseDSModel:
Expand Down
4 changes: 1 addition & 3 deletions deepsearch/model/kinds/qagen/controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Literal

from fastapi import HTTPException, status

from deepsearch.model.base.controller import BaseController
Expand Down Expand Up @@ -34,7 +32,7 @@ def get_info(self) -> QAGenInfoOutput:
def _get_model(self) -> BaseDSModel:
return self._model

def get_kind(self) -> Literal[Kind.QAGenModel]:
def get_kind(self) -> str:
return Kind.QAGenModel

def dispatch_predict(self, spec: CtrlPredInput) -> CtrlPredOutput:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ py_version=38
known_first_party = ["cps"]

[tool.mypy]
plugins = ["pydantic.mypy"]
pretty = true
# strict = true
no_implicit_optional = true
Expand Down

0 comments on commit 2360254

Please sign in to comment.