Skip to content

Commit

Permalink
linted
Browse files Browse the repository at this point in the history
  • Loading branch information
ncilfone committed Mar 11, 2022
1 parent e29a618 commit 7d63093
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 23 deletions.
1 change: 0 additions & 1 deletion spock/backend/builder.py
Expand Up @@ -20,7 +20,6 @@
from spock.graph import Graph
from spock.utils import make_argument


minor = sys.version_info.minor
if minor < 7:
from typing import CallableMeta as _VariadicGenericAlias
Expand Down
2 changes: 1 addition & 1 deletion spock/backend/config.py
Expand Up @@ -118,7 +118,7 @@ def _process_class(cls, kw_only: bool, make_init: bool, dynamic: bool):
init=make_init,
)
# Copy over the post init function
if hasattr(cls, '__post_hook__'):
if hasattr(cls, "__post_hook__"):
obj.__post_hook__ = cls.__post_hook__
# For each class we dynamically create we need to register it within the system modules for pickle to work
setattr(sys.modules["spock"].backend.config, obj.__name__, obj)
Expand Down
20 changes: 12 additions & 8 deletions spock/backend/field_handlers.py
Expand Up @@ -5,20 +5,22 @@

"""Handles registering field attributes for spock classes -- deals with the recursive nature of dependencies"""

import importlib
import sys
from abc import ABC, abstractmethod
from enum import EnumMeta
from typing import List, Type

from attr import NOTHING, Attribute

import importlib

from spock.backend.spaces import AttributeSpace, BuilderSpace, ConfigSpace
from spock.exceptions import _SpockInstantiationError, _SpockNotOptionalError, _SpockValueError
from spock.exceptions import (
_SpockInstantiationError,
_SpockNotOptionalError,
_SpockValueError,
)
from spock.utils import _check_iterable, _is_spock_instance, _is_spock_tune_instance


minor = sys.version_info.minor
if minor < 7:
from typing import CallableMeta as _VariadicGenericAlias
Expand Down Expand Up @@ -354,10 +356,12 @@ def handle_attribute_from_config(
Returns:
"""
# These are always going to be strings... cast just in case
str_field = str(builder_space.arguments[attr_space.config_space.name][
attr_space.attribute.name
])
module, fn = str_field.rsplit('.', 1)
str_field = str(
builder_space.arguments[attr_space.config_space.name][
attr_space.attribute.name
]
)
module, fn = str_field.rsplit(".", 1)
try:
call_ref = getattr(importlib.import_module(module), fn)
attr_space.field = call_ref
Expand Down
4 changes: 3 additions & 1 deletion spock/backend/saver.py
Expand Up @@ -146,7 +146,9 @@ def _clean_output(self, out_dict):
for idx, list_val in enumerate(val):
tmp_dict = {}
for inner_key, inner_val in list_val.items():
tmp_dict = self._convert_tuples_2_lists(tmp_dict, inner_val, inner_key)
tmp_dict = self._convert_tuples_2_lists(
tmp_dict, inner_val, inner_key
)
val[idx] = tmp_dict
clean_inner_dict = val
else:
Expand Down
2 changes: 1 addition & 1 deletion spock/backend/typed.py
Expand Up @@ -16,8 +16,8 @@

minor = sys.version_info.minor
if minor < 7:
from typing import GenericMeta as _GenericAlias
from typing import CallableMeta as _VariadicGenericAlias
from typing import GenericMeta as _GenericAlias
else:
from typing import _GenericAlias, _VariadicGenericAlias

Expand Down
1 change: 1 addition & 0 deletions spock/exceptions.py
Expand Up @@ -3,6 +3,7 @@
# Copyright FMR LLC <opensource@fidelity.com>
# SPDX-License-Identifier: Apache-2.0


class _SpockUndecoratedClass(Exception):
"""Custom exception type for non spock decorated classes and not dynamic"""

Expand Down
38 changes: 27 additions & 11 deletions spock/utils.py
Expand Up @@ -10,26 +10,31 @@
import socket
import subprocess
import sys
from time import localtime, strftime
from warnings import warn

from spock.exceptions import _SpockValueError

from enum import EnumMeta
from pathlib import Path
from time import localtime, strftime
from typing import List, Type, Union
from warnings import warn

import attr
import git

from spock.exceptions import _SpockValueError

minor = sys.version_info.minor
if minor < 7:
from typing import GenericMeta as _GenericAlias
else:
from typing import _GenericAlias


def within(val: Union[float, int], low_bound: Union[float, int], upper_bound: Union[float, int], inclusive_lower: bool = False, inclusive_upper: bool = False) -> None:
def within(
val: Union[float, int],
low_bound: Union[float, int],
upper_bound: Union[float, int],
inclusive_lower: bool = False,
inclusive_upper: bool = False,
) -> None:
"""Checks that a value is within a defined range
Args:
Expand Down Expand Up @@ -68,7 +73,9 @@ def ge(val: Union[float, int], bound: Union[float, int]) -> None:
"""
if val < bound:
raise _SpockValueError(f"Set value `{val}` is not >= given bound value `{bound}`")
raise _SpockValueError(
f"Set value `{val}` is not >= given bound value `{bound}`"
)


def gt(val: Union[float, int], bound: Union[float, int]) -> None:
Expand All @@ -86,10 +93,15 @@ def gt(val: Union[float, int], bound: Union[float, int]) -> None:
"""
if val <= bound:
raise _SpockValueError(f"Set value `{val}` is not > given bound value `{bound}`")
raise _SpockValueError(
f"Set value `{val}` is not > given bound value `{bound}`"
)


def le(val: Union[float, int], bound: Union[float, int], ) -> None:
def le(
val: Union[float, int],
bound: Union[float, int],
) -> None:
"""Checks that a value is less than or equal to (inclusive) an upper bound
Args:
Expand All @@ -104,7 +116,9 @@ def le(val: Union[float, int], bound: Union[float, int], ) -> None:
"""
if val > bound:
raise _SpockValueError(f"Set value `{val}` is not <= given bound value `{bound}`")
raise _SpockValueError(
f"Set value `{val}` is not <= given bound value `{bound}`"
)


def lt(val: Union[float, int], bound: Union[float, int]) -> None:
Expand All @@ -122,7 +136,9 @@ def lt(val: Union[float, int], bound: Union[float, int]) -> None:
"""
if val >= bound:
raise _SpockValueError(f"Set value `{val}` is not < given bound value `{bound}`")
raise _SpockValueError(
f"Set value `{val}` is not < given bound value `{bound}`"
)


def _find_all_spock_classes(attr_class: Type):
Expand Down

0 comments on commit 7d63093

Please sign in to comment.