Skip to content

Commit

Permalink
[BugFix] Run ruff check --fix (#6984)
Browse files Browse the repository at this point in the history
* run ruff check --fix on openbb-core

* rest of the repo

* black

* type: ignore

* more linting
  • Loading branch information
deeleeramone authored Dec 7, 2024
1 parent bed3aa0 commit 7d7456a
Show file tree
Hide file tree
Showing 205 changed files with 227 additions and 430 deletions.
4 changes: 2 additions & 2 deletions cli/openbb_cli/argparse_translator/obbject_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ def _handle_data_repr(obbject: OBBject) -> str:
else ""
)
if data_schema and "title" in data_schema:
data_repr = f"{data_schema['title']}"
data_repr = f"{data_schema['title']}" # type: ignore
if data_schema and "description" in data_schema:
data_repr += f" - {data_schema['description'].split('.')[0]}"
data_repr += f" - {data_schema['description'].split('.')[0]}" # type: ignore

return data_repr

Expand Down
8 changes: 4 additions & 4 deletions cli/openbb_cli/controllers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def parse_and_split_input(an_input: str, custom_filters: List) -> List[str]:
commands = an_input.split("/") if "timezone" not in an_input else [an_input]

for command_num, command in enumerate(commands):
if command == commands[command_num] == commands[-1] == "":
if command == commands[-1] == "":
return list(filter(None, commands))
matching_placeholders = [tag for tag in placeholders if tag in command]
if len(matching_placeholders) > 0:
Expand Down Expand Up @@ -300,7 +300,7 @@ def return_colored_value(value: str):
return f"{value}"


# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments,too-many-positional-arguments
def print_rich_table( # noqa: PLR0912
df: pd.DataFrame,
show_index: bool = False,
Expand Down Expand Up @@ -753,7 +753,7 @@ def ask_file_overwrite(file_path: Path) -> Tuple[bool, bool]:


# This is a false positive on pylint and being tracked in pylint #3060
# pylint: disable=abstract-class-instantiated
# pylint: disable=abstract-class-instantiated,too-many-positional-arguments
def save_to_excel(df, saved_path, sheet_name, start_row=0, index=True, header=True):
"""Save a Pandas DataFrame to an Excel file.
Expand Down Expand Up @@ -803,7 +803,7 @@ def save_to_excel(df, saved_path, sheet_name, start_row=0, index=True, header=Tr


# This is a false positive on pylint and being tracked in pylint #3060
# pylint: disable=abstract-class-instantiated
# pylint: disable=abstract-class-instantiated,too-many-positional-arguments
def export_data(
export_type: str,
dir_path: str,
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_controllers_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_get_flair_and_username(mock_session):
"""Test getting the flair and username."""
result = get_flair_and_username()
assert "testuser" in result
assert "rocket" in result #
assert "rocket" in result


@pytest.mark.parametrize(
Expand Down
4 changes: 1 addition & 3 deletions openbb_platform/core/openbb_core/api/router/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ async def wrapper(*args: Tuple[Any], **kwargs: Dict[str, Any]) -> OBBject:
)

if defaults:
provider_choices = getattr(
kwargs.get("provider_choices", None), "__dict__", {}
)
provider_choices = getattr(kwargs.get("provider_choices"), "__dict__", {})
_provider = defaults.pop("provider", None)

if (
Expand Down
5 changes: 2 additions & 3 deletions openbb_platform/core/openbb_core/app/command_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Type
from warnings import catch_warnings, showwarning, warn

from pydantic import BaseModel, ConfigDict, create_model

from openbb_core.app.model.abstract.error import OpenBBError
from openbb_core.app.model.abstract.warning import OpenBBWarning, cast_warning
from openbb_core.app.model.metadata import Metadata
from openbb_core.app.model.obbject import OBBject
from openbb_core.app.provider_interface import ExtraParams
from openbb_core.env import Env
from openbb_core.provider.utils.helpers import maybe_coroutine, run_async
from pydantic import BaseModel, ConfigDict, create_model

if TYPE_CHECKING:
from openbb_core.app.model.system_settings import SystemSettings
Expand Down Expand Up @@ -273,7 +272,7 @@ def _extract_params(cls, kwargs, key) -> Dict:

# pylint: disable=R0913, R0914
@classmethod
async def _execute_func(
async def _execute_func( # pylint: disable=too-many-positional-arguments
cls,
route: str,
args: Tuple[Any, ...],
Expand Down
1 change: 0 additions & 1 deletion openbb_platform/core/openbb_core/app/extension_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import TYPE_CHECKING, Any, Dict, List, Optional

from importlib_metadata import EntryPoint, EntryPoints, entry_points

from openbb_core.app.model.abstract.singleton import SingletonMeta
from openbb_core.app.model.extension import Extension

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Command Context."""

from pydantic import BaseModel, Field

from openbb_core.app.model.system_settings import SystemSettings
from openbb_core.app.model.user_settings import UserSettings
from pydantic import BaseModel, Field


class CommandContext(BaseModel):
Expand Down
9 changes: 4 additions & 5 deletions openbb_platform/core/openbb_core/app/model/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import warnings
from typing import Dict, List, Optional, Tuple

from openbb_core.app.extension_loader import ExtensionLoader
from openbb_core.app.model.abstract.warning import OpenBBWarning
from openbb_core.app.provider_interface import ProviderInterface
from openbb_core.env import Env
from pydantic import (
BaseModel,
ConfigDict,
Expand All @@ -14,11 +18,6 @@
from pydantic.functional_serializers import PlainSerializer
from typing_extensions import Annotated

from openbb_core.app.extension_loader import ExtensionLoader
from openbb_core.app.model.abstract.warning import OpenBBWarning
from openbb_core.app.provider_interface import ProviderInterface
from openbb_core.env import Env


class LoadingError(Exception):
"""Error loading extension."""
Expand Down
3 changes: 1 addition & 2 deletions openbb_platform/core/openbb_core/app/model/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from typing import Any
from warnings import warn

from pydantic import BaseModel, ConfigDict, Field, model_validator

from openbb_core.app.model.abstract.warning import OpenBBWarning
from pydantic import BaseModel, ConfigDict, Field, model_validator


class Defaults(BaseModel):
Expand Down
3 changes: 1 addition & 2 deletions openbb_platform/core/openbb_core/app/model/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from datetime import datetime
from typing import Any, Dict, Optional, Sequence, Union

from pydantic import BaseModel, Field, field_validator

from openbb_core.provider.abstract.data import Data
from pydantic import BaseModel, Field, field_validator


class Metadata(BaseModel):
Expand Down
3 changes: 1 addition & 2 deletions openbb_platform/core/openbb_core/app/model/obbject.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
Union,
)

from pydantic import BaseModel, Field, PrivateAttr

from openbb_core.app.model.abstract.error import OpenBBError
from openbb_core.app.model.abstract.tagged import Tagged
from openbb_core.app.model.abstract.warning import Warning_
from openbb_core.app.model.charts.chart import Chart
from openbb_core.provider.abstract.annotated_result import AnnotatedResult
from openbb_core.provider.abstract.data import Data
from pydantic import BaseModel, Field, PrivateAttr

if TYPE_CHECKING:
from numpy import ndarray # noqa
Expand Down
3 changes: 1 addition & 2 deletions openbb_platform/core/openbb_core/app/model/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from typing import Optional

from pydantic import BaseModel, ConfigDict, Field

from openbb_core.app.model.hub.hub_session import HubSession
from pydantic import BaseModel, ConfigDict, Field


class Profile(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from pathlib import Path
from typing import List, Literal, Optional

from pydantic import ConfigDict, Field, field_validator, model_validator

from openbb_core.app.constants import (
HOME_DIRECTORY,
OPENBB_DIRECTORY,
Expand All @@ -17,6 +15,7 @@
from openbb_core.app.model.api_settings import APISettings
from openbb_core.app.model.python_settings import PythonSettings
from openbb_core.app.version import CORE_VERSION, VERSION
from pydantic import ConfigDict, Field, field_validator, model_validator


class SystemSettings(Tagged):
Expand Down
3 changes: 1 addition & 2 deletions openbb_platform/core/openbb_core/app/model/user_settings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""User settings model."""

from pydantic import Field

from openbb_core.app.model.abstract.tagged import Tagged
from openbb_core.app.model.credentials import Credentials
from openbb_core.app.model.defaults import Defaults
from openbb_core.app.model.preferences import Preferences
from openbb_core.app.model.profile import Profile
from pydantic import Field


class UserSettings(Tagged):
Expand Down
11 changes: 5 additions & 6 deletions openbb_platform/core/openbb_core/app/provider_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
)

from fastapi import Body, Query
from openbb_core.app.model.abstract.singleton import SingletonMeta
from openbb_core.app.model.obbject import OBBject
from openbb_core.provider.query_executor import QueryExecutor
from openbb_core.provider.registry_map import MapType, RegistryMap
from openbb_core.provider.utils.helpers import to_snake_case
from pydantic import (
BaseModel,
ConfigDict,
Expand All @@ -27,12 +32,6 @@
)
from pydantic.fields import FieldInfo

from openbb_core.app.model.abstract.singleton import SingletonMeta
from openbb_core.app.model.obbject import OBBject
from openbb_core.provider.query_executor import QueryExecutor
from openbb_core.provider.registry_map import MapType, RegistryMap
from openbb_core.provider.utils.helpers import to_snake_case

TupleFieldType = Tuple[str, Optional[Type], Optional[Any]]


Expand Down
7 changes: 3 additions & 4 deletions openbb_platform/core/openbb_core/app/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
)

from fastapi import APIRouter, Depends
from pydantic import BaseModel
from pydantic.v1.validators import find_validators
from typing_extensions import Annotated, ParamSpec, _AnnotatedAlias

from openbb_core.app.deprecation import DeprecationSummary, OpenBBDeprecationWarning
from openbb_core.app.extension_loader import ExtensionLoader
from openbb_core.app.model.abstract.warning import OpenBBWarning
Expand All @@ -35,6 +31,9 @@
StandardParams,
)
from openbb_core.env import Env
from pydantic import BaseModel
from pydantic.v1.validators import find_validators
from typing_extensions import Annotated, ParamSpec, _AnnotatedAlias

P = ParamSpec("P")

Expand Down
25 changes: 8 additions & 17 deletions openbb_platform/core/openbb_core/app/static/package_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import inspect
import re
import shutil
import sys
from dataclasses import Field as DCField
from functools import partial
from inspect import Parameter, _empty, isclass, signature
Expand All @@ -31,11 +30,6 @@
)

from importlib_metadata import entry_points
from pydantic.fields import FieldInfo
from pydantic_core import PydanticUndefined
from starlette.routing import BaseRoute
from typing_extensions import Annotated, _AnnotatedAlias

from openbb_core.app.extension_loader import ExtensionLoader, OpenBBGroups
from openbb_core.app.model.example import Example
from openbb_core.app.model.field import OpenBBField
Expand All @@ -47,6 +41,10 @@
from openbb_core.app.static.utils.linters import Linters
from openbb_core.app.version import CORE_VERSION, VERSION
from openbb_core.env import Env
from pydantic.fields import FieldInfo
from pydantic_core import PydanticUndefined
from starlette.routing import BaseRoute
from typing_extensions import Annotated, _AnnotatedAlias

if TYPE_CHECKING:
# pylint: disable=import-outside-toplevel
Expand Down Expand Up @@ -377,18 +375,11 @@ def build(cls, path: str) -> str:
code += "\nfrom typing import TYPE_CHECKING, ForwardRef, List, Dict, Union, Optional, Literal, Any"
code += "\nfrom annotated_types import Ge, Le, Gt, Lt"
code += "\nfrom warnings import warn, simplefilter"
if sys.version_info < (3, 9):
code += "\nimport typing_extensions"
else:
code += "\nfrom typing_extensions import Annotated, deprecated"
# code += "\nfrom openbb_core.app.utils import df_to_basemodel"
code += "\nfrom typing_extensions import Annotated, deprecated"
code += "\nfrom openbb_core.app.static.utils.decorators import exception_handler, validate\n"
code += "\nfrom openbb_core.app.static.utils.filters import filter_inputs\n"
code += "\nfrom openbb_core.app.deprecation import OpenBBDeprecationWarning\n"
code += "\nfrom openbb_core.app.model.field import OpenBBField"
# if path.startswith("/quantitative"):
# code += "\nfrom openbb_quantitative.models import "
# code += "(CAPMModel,NormalityModel,OmegaModel,SummaryModel,UnitRootModel)"
module_list = [hint_type.__module__ for hint_type in hint_type_list]
module_list = list(set(module_list))
module_list.sort()
Expand Down Expand Up @@ -1054,7 +1045,7 @@ def build_examples(
return ""

@classmethod
def generate_model_docstring(
def generate_model_docstring( # pylint: disable=too-many-positional-arguments
cls,
model_name: str,
summary: str,
Expand Down Expand Up @@ -1104,7 +1095,7 @@ def get_param_info(parameter: Optional[Parameter]) -> Tuple[str, str]:
)
metadata = getattr(annotation, "__metadata__", [])
description = getattr(metadata[0], "description", "") if metadata else ""
return type_, description
return type_, description # type: ignore

# Description summary
if "description" in sections:
Expand Down Expand Up @@ -1159,7 +1150,7 @@ def get_param_info(parameter: Optional[Parameter]) -> Tuple[str, str]:
return docstring

@classmethod
def generate(
def generate( # pylint: disable=too-many-positional-arguments
cls,
path: str,
func: Callable,
Expand Down
4 changes: 2 additions & 2 deletions openbb_platform/core/openbb_core/app/static/utils/linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def run(
command = [linter]
if flags:
command.extend(flags) # type: ignore
subprocess.run(
command + list(self.directory.glob("*.py")), check=False # noqa: S603
subprocess.run( # noqa: S603
command + list(self.directory.glob("*.py")), check=False
)

self.print_separator("-")
Expand Down
3 changes: 1 addition & 2 deletions openbb_platform/core/openbb_core/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
from datetime import time
from typing import TYPE_CHECKING, Dict, List, Optional, Union

from pydantic import ValidationError

from openbb_core.app.model.abstract.error import OpenBBError
from openbb_core.app.model.preferences import Preferences
from openbb_core.app.model.system_settings import SystemSettings
from openbb_core.provider.abstract.data import Data
from pydantic import ValidationError

if TYPE_CHECKING:
# pylint: disable=import-outside-toplevel
Expand Down
4 changes: 2 additions & 2 deletions openbb_platform/core/openbb_core/app/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def is_git_repo(path: Path):
if not git_executable:
return False
try:
subprocess.run(
[git_executable, "rev-parse", "--is-inside-work-tree"], # noqa: S603
subprocess.run( # noqa: S603
[git_executable, "rev-parse", "--is-inside-work-tree"],
cwd=path,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
Expand Down
1 change: 0 additions & 1 deletion openbb_platform/core/openbb_core/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Dict, Optional

import dotenv

from openbb_core.app.constants import OPENBB_DIRECTORY
from openbb_core.app.model.abstract.singleton import SingletonMeta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def data_type(self) -> D: # type: ignore
@staticmethod
def _get_data_type(data: Any) -> D: # type: ignore
"""Get the type of the data."""
if get_origin(data) == list:
if get_origin(data) is list:
data = get_args(data)[0]
return data

Expand Down
Loading

0 comments on commit 7d7456a

Please sign in to comment.