Skip to content

Commit

Permalink
fix minor codestyle issues
Browse files Browse the repository at this point in the history
  • Loading branch information
benvanwerkhoven committed Jun 28, 2024
1 parent 6a7581d commit 63ce10c
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions kernel_tuner/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@

import json
from collections import OrderedDict
from collections.abc import Mapping
from datetime import datetime
from functools import cached_property
from functools import lru_cache as cache
from os import PathLike
from pathlib import Path
from typing import Any, Dict, Iterable, Iterator, Optional, Tuple, Union, cast
from typing import Any, Optional, Union, cast

import jsonschema
import kernel_tuner.util as util
import numpy as np
from kernel_tuner import util
from semver import Version

from .convert import convert_cache
from .file import append_cache_line
from .json import CacheFileJSON, CacheLineJSON
from .paths import get_schema_path
from .versions import LATEST_VERSION, VERSIONS

Expand Down Expand Up @@ -259,7 +257,7 @@ def get_from_params(self, default=None, **params) -> Union[Cache.Line, list[Cach
results = [self[k] for k in line_ids]
if not results:
return default
elif len(results) == 1:
if len(results) == 1:
results = results[0]
return results

Expand Down Expand Up @@ -297,7 +295,7 @@ def __get_line_id_from_tune_params_dict(self, tune_params: dict) -> str:
class ReadableLines(Lines):
"""Cache lines in a read_only cache file."""

def append(*args, **kwargs):
def append(self, *args, **kwargs):
"""Method to append lines to cache file, should not happen with read-only cache"""
raise ValueError("Attempting to write to read-only cache")

Expand All @@ -312,7 +310,7 @@ def __init__(self, *args, **kwargs):
def __getattr__(self, name):
if not name.startswith("_"):
return self[name]
return super(Line, self).__getattr__(name)
return super(dict, self).__getattr__(name)


def _encode_cache_line(line_id, line):
Expand Down Expand Up @@ -370,9 +368,9 @@ def default(self, o):
return float(o)
elif isinstance(o, np.ndarray):
return o.tolist()
super().default(o)
return super().default(o)

def iterencode(self, obj, *args, **kwargs):
def iterencode(self, obj, **kwargs):
"""encode an iterator, ensuring 'cache' is the last entry for encoded dicts"""

# ensure key 'cache' is last in any encoded dictionary
Expand All @@ -381,7 +379,7 @@ def iterencode(self, obj, *args, **kwargs):
if "cache" in obj:
obj.move_to_end("cache")

yield from super().iterencode(obj, *args, **kwargs)
yield from super().iterencode(obj, **kwargs)


def read_cache_file(filename: PathLike):
Expand All @@ -397,7 +395,7 @@ def read_cache_file(filename: PathLike):
try:
data = json.load(file)
except json.JSONDecodeError as e:
raise InvalidCacheError(filename, "Cache file is not parsable", e)
raise InvalidCacheError(filename, "Cache file is not parsable", e) from e
return data


Expand Down

0 comments on commit 63ce10c

Please sign in to comment.