Skip to content

Commit

Permalink
Pull in changes from 3.10 bump and ruff pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasjng committed Oct 1, 2024
1 parent 6fc5c71 commit 00adb83
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 49 deletions.
2 changes: 1 addition & 1 deletion examples/huggingface/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import tempfile
import time
from collections.abc import Sequence
from functools import cache, lru_cache, partial
from typing import Sequence

import torch
from datasets import Dataset, load_dataset
Expand Down
2 changes: 1 addition & 1 deletion examples/mnist/mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"""

import random
from collections.abc import Mapping
from dataclasses import dataclass
from pathlib import Path
from typing import Mapping

import flax.linen as nn
import fsspec
Expand Down
2 changes: 0 additions & 2 deletions examples/prefect/src/runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import asyncio
import os

Expand Down
2 changes: 0 additions & 2 deletions examples/prefect/src/training.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import numpy as np
from prefect import flow, task
from sklearn import base
Expand Down
8 changes: 3 additions & 5 deletions src/nnbench/context.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""Utilities for collecting context key-value pairs as metadata in benchmark runs."""

from __future__ import annotations

import itertools
import platform
import sys
from typing import Any, Callable, Iterator, Literal
from collections.abc import Callable, Iterator
from typing import Any, Literal

ContextProvider = Callable[[], dict[str, Any]]
"""A function providing a dictionary of context values."""
Expand Down Expand Up @@ -89,8 +88,7 @@ def git_subprocess(args: list[str]) -> subprocess.CompletedProcess:

return subprocess.run( # nosec: B603
[git, *args],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,
encoding="utf-8",
)

Expand Down
5 changes: 2 additions & 3 deletions src/nnbench/core.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Data model, registration, and parametrization facilities for defining benchmarks."""

from __future__ import annotations

import inspect
import itertools
import sys
import types
import warnings
from typing import Any, Callable, Iterable, Union, get_args, get_origin, overload
from collections.abc import Callable, Iterable
from typing import Any, Union, get_args, get_origin, overload

from nnbench.types import Benchmark
from nnbench.types.benchmark import NoOp
Expand Down
2 changes: 0 additions & 2 deletions src/nnbench/reporter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
A lightweight interface for refining, displaying, and streaming benchmark results to various sinks.
"""

from __future__ import annotations

from .base import BenchmarkReporter
from .duckdb_sql import DuckDBReporter
from .file import FileReporter
5 changes: 2 additions & 3 deletions src/nnbench/reporter/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import re
from typing import Any, Callable
from collections.abc import Callable
from typing import Any

from tabulate import tabulate

Expand Down
4 changes: 1 addition & 3 deletions src/nnbench/reporter/duckdb_sql.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import os
import shutil
import sys
Expand Down Expand Up @@ -130,6 +128,6 @@ def read_sql(

return BenchmarkRecord(context=context, benchmarks=benchmarks)

def raw_sql(self, query: str) -> duckdb.DuckDBPyRelation:
def raw_sql(self, query: str) -> "duckdb.DuckDBPyRelation":
rel = self.conn.sql(query=query)
return rel
5 changes: 2 additions & 3 deletions src/nnbench/reporter/file.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from __future__ import annotations

import os
import threading
from collections.abc import Callable, Sequence
from dataclasses import dataclass, field
from pathlib import Path
from typing import IO, Any, Callable, Literal, Sequence, cast
from typing import IO, Any, Literal, cast

from nnbench.reporter.base import BenchmarkReporter
from nnbench.types import BenchmarkRecord
Expand Down
7 changes: 3 additions & 4 deletions src/nnbench/runner.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""The abstract benchmark runner interface, which can be overridden for custom benchmark workloads."""

from __future__ import annotations

import collections
import contextlib
import inspect
Expand All @@ -10,10 +8,11 @@
import sys
import time
import warnings
from collections.abc import Callable, Generator, Sequence
from dataclasses import asdict
from datetime import datetime
from pathlib import Path
from typing import Any, Callable, Generator, Sequence, get_origin
from typing import Any, get_origin

from nnbench.context import Context, ContextProvider
from nnbench.types import Benchmark, BenchmarkRecord, Parameters, State
Expand All @@ -24,7 +23,7 @@


def iscontainer(s: Any) -> bool:
return isinstance(s, (tuple, list))
return isinstance(s, tuple | list)


def isdunder(s: str) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion src/nnbench/transforms/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Metaclasses for defining transforms acting on benchmark records."""

from abc import ABC, abstractmethod
from typing import Sequence
from collections.abc import Sequence

from nnbench.types import BenchmarkRecord

Expand Down
3 changes: 2 additions & 1 deletion src/nnbench/transforms/params.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Sequence
from collections.abc import Sequence
from typing import Any

from nnbench.transforms import ManyToManyTransform, OneToOneTransform
from nnbench.types import BenchmarkRecord
Expand Down
17 changes: 9 additions & 8 deletions src/nnbench/types/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
"""Type interfaces for benchmarks and benchmark collections."""

from __future__ import annotations

import copy
from collections.abc import Callable, Mapping
from dataclasses import dataclass, field
from types import MappingProxyType
from typing import Any, Callable, Literal, Mapping
from typing import Any, Literal

from typing_extensions import Self

from nnbench.context import Context
from nnbench.types.interface import Interface


def NoOp(state: State, params: Mapping[str, Any] = MappingProxyType({})) -> None:
pass


@dataclass(frozen=True)
class State:
name: str
Expand All @@ -23,6 +20,10 @@ class State:
family_index: int


def NoOp(state: State, params: Mapping[str, Any] = MappingProxyType({})) -> None:
pass


@dataclass(frozen=True)
class BenchmarkRecord:
context: Context
Expand Down Expand Up @@ -68,7 +69,7 @@ def compact(
return result

@classmethod
def expand(cls, bms: list[dict[str, Any]]) -> BenchmarkRecord:
def expand(cls, bms: list[dict[str, Any]]) -> Self:
"""
Expand a list of deserialized JSON-like objects into a benchmark record.
This is equivalent to extracting the context given by the method it was
Expand Down
9 changes: 5 additions & 4 deletions src/nnbench/types/interface.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Type interface for the function interface"""

from __future__ import annotations

import inspect
from collections.abc import Callable
from dataclasses import dataclass
from typing import Any, Callable, TypeVar
from typing import Any, TypeVar

from typing_extensions import Self

T = TypeVar("T")
Variable = tuple[str, type, Any]
Expand Down Expand Up @@ -37,7 +38,7 @@ class Interface:
returntype: type

@classmethod
def from_callable(cls, fn: Callable, defaults: dict[str, Any]) -> Interface:
def from_callable(cls, fn: Callable, defaults: dict[str, Any]) -> Self:
"""
Creates an interface instance from the given callable.
"""
Expand Down
5 changes: 2 additions & 3 deletions src/nnbench/types/memo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import annotations

import collections
import functools
import inspect
import logging
import threading
from typing import Any, Callable, Generic, TypeVar, get_args, get_origin
from collections.abc import Callable
from typing import Any, Generic, TypeVar, get_args, get_origin

T = TypeVar("T")
Variable = tuple[str, type, Any]
Expand Down
2 changes: 0 additions & 2 deletions src/nnbench/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Various utilities related to benchmark collection, filtering, and more."""

from __future__ import annotations

import importlib
import importlib.util
import os
Expand Down
2 changes: 1 addition & 1 deletion tests/test_memos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Generator
from collections.abc import Generator

import pytest

Expand Down

0 comments on commit 00adb83

Please sign in to comment.