Skip to content

Commit

Permalink
code style tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
diceroll123 committed Jan 30, 2024
1 parent 434231c commit 3f8e65b
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 67 deletions.
6 changes: 3 additions & 3 deletions neofoodclub/arenas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Generator, Iterator, Sequence
from typing import TYPE_CHECKING, Iterator, Sequence

from . import math
from .pirates import Pirate
Expand Down Expand Up @@ -102,7 +102,7 @@ def __getitem__(self, item: int) -> Pirate:
return self._pirates[item]

def __iter__(self) -> Iterator[Pirate]:
return self._pirates.__iter__()
return iter(self._pirates)

def __repr__(self) -> str:
return (
Expand Down Expand Up @@ -181,7 +181,7 @@ def get_arena(self, arena_id: int, /) -> Arena:
def __getitem__(self, key: int) -> Arena:
return self._arenas[key]

def __iter__(self) -> Generator[Arena, None, None]:
def __iter__(self) -> Iterator[Arena]:
yield from self._arenas

def __repr__(self) -> str:
Expand Down
9 changes: 5 additions & 4 deletions neofoodclub/bets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Generator, Sequence
from itertools import starmap
from typing import TYPE_CHECKING, Any, Generator, Iterator, Sequence

import numpy as np

Expand Down Expand Up @@ -137,7 +138,7 @@ def __repr__(self) -> str:
("bets_hash", self.bets_hash),
("amounts_hash", self.amounts_hash),
]
joined = " ".join("{}={!r}".format(*t) for t in attrs)
joined = " ".join(starmap("{}={!r}".format, attrs))
return f"<Bets {joined}>"

@classmethod
Expand Down Expand Up @@ -360,10 +361,10 @@ def _iterator(self) -> Generator[int, None, None]:
int_bins = self.nfc._data_dict["bins"]
yield from int_bins[self._indices]

def __iter__(self) -> Generator[int, None, None]:
def __iter__(self) -> Iterator[int]:
return self._iterator()

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return (
isinstance(other, self.__class__)
and self.bets_hash == other.bets_hash
Expand Down
5 changes: 0 additions & 5 deletions neofoodclub/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@ class FoodClubException(Exception):
"""Base exception class for neofoodclub.py."""



class InvalidData(FoodClubException):
"""An exception that is thrown when improper data is passed into creating NFC objects."""



class NoPositiveArenas(FoodClubException):
"""An exception that is thrown when there are no positive arenas while creating a bustproof set."""



class InvalidBetHash(FoodClubException):
"""An exception that is thrown when an improper string is used to create bets from a hash."""



class InvalidAmountHash(FoodClubException):
"""An exception that is thrown when an improper string is used to create bet amounts from a hash."""

2 changes: 1 addition & 1 deletion neofoodclub/food_adjustments.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __new__(
*,
one: tuple[int, ...] | None = None,
two: tuple[int, ...] | None = None,
) -> DefaultDict[int, int]:
) -> defaultdict[int, int]:
data: dict[int, int] = {}

for fa_value, values in zip((1, 2), (one, two)):
Expand Down
4 changes: 2 additions & 2 deletions neofoodclub/modifier.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import datetime
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from neofoodclub.nfc import NeoFoodClub
Expand Down Expand Up @@ -181,7 +181,7 @@ def letters(self) -> str:
if self._has_flag(1 << bit)
)

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return (
isinstance(other, self.__class__)
and self.value == other.value
Expand Down
6 changes: 0 additions & 6 deletions neofoodclub/neofoodclub.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def pirate_binary_rust(index: int, arena: int) -> int:
arena: :class:`int`
The arena's index. Can be 0 to 4.
"""
...

def pirates_binary_rust(bets_indices: Sequence[int]) -> int:
""":class:`int`: Returns the bet-binary representation of bet indices.
Expand All @@ -32,7 +31,6 @@ def pirates_binary_rust(bets_indices: Sequence[int]) -> int:
bets_indices: Sequence[:class:`int`]
A sequence of integers from 0 to 4 to represent a bet.
"""
...

def binary_to_indices_rust(bet_binary: int) -> tuple[int, ...]:
"""Tuple[int, ...]: Returns the bet indices of a bet-binary value.
Expand All @@ -42,7 +40,6 @@ def binary_to_indices_rust(bet_binary: int) -> tuple[int, ...]:
bet_binary: :class:`int`
An integer representing a bet.
"""
...

def bets_hash_to_bet_indices_rust(bets_hash: str) -> list[list[int]]:
"""List[List[:class:`int`]]: Returns a list of lists of bet indices from the provided bets hash.
Expand All @@ -52,7 +49,6 @@ def bets_hash_to_bet_indices_rust(bets_hash: str) -> list[list[int]]:
bets_hash: :class:`str`
The hash of bet amounts.
"""
...

def bet_amounts_to_amounts_hash_rust(bet_amounts: Sequence[int]) -> str:
""":class:`str`: Returns the hash for the provided bet amounts.
Expand All @@ -64,7 +60,6 @@ def bet_amounts_to_amounts_hash_rust(bet_amounts: Sequence[int]) -> str:
bet_amounts: Sequence[int]
A sequence of bet amount integers.
"""
...

def bets_hash_value_rust(bets_indices: Sequence[Sequence[int]]) -> str:
""":class:`str`: Returns a hash for the bets indices provided.
Expand All @@ -74,7 +69,6 @@ def bets_hash_value_rust(bets_indices: Sequence[Sequence[int]]) -> str:
bets_indices: Sequence[Sequence[:class:`int`]]
A sequence of a sequence of integers from 0 to 4 to represent a bet.
"""
...

def make_probabilities_rust(
opening_odds: Sequence[Sequence[int]],
Expand Down
3 changes: 2 additions & 1 deletion neofoodclub/nfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import contextlib
import datetime
import functools
import operator
import re
import urllib.parse
from typing import TYPE_CHECKING, Any, Callable, Sequence, TypeVar, overload
Expand Down Expand Up @@ -609,7 +610,7 @@ def from_url(
raise InvalidData("NeoFoodClub URL parameter `pirates` is invalid.")

pirate_lists = orjson.loads(pirate_string)
has_proper_ids = set(sum(pirate_lists, [])) == set(range(1, 21))
has_proper_ids = set(functools.reduce(operator.iadd, pirate_lists, [])) == set(range(1, 21))
if not has_proper_ids:
raise InvalidData("NeoFoodClub URL parameter `pirates` is invalid.")

Expand Down
7 changes: 4 additions & 3 deletions neofoodclub/odds.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Generator
from itertools import starmap
from typing import TYPE_CHECKING, Generator, Iterator

from neofoodclub import math

Expand Down Expand Up @@ -63,7 +64,7 @@ def __init__(self, bets: Bets) -> None:
def _iterator(self) -> Generator[int, None, None]:
yield from self._odds_values

def __iter__(self) -> Generator[int, None, None]:
def __iter__(self) -> Iterator[int]:
return self._iterator()

def __repr__(self) -> str:
Expand All @@ -73,5 +74,5 @@ def __repr__(self) -> str:
("most_likely_winner", self.most_likely_winner),
("partial_rate", self.partial_rate),
]
joined = " ".join("{}={!r}".format(*t) for t in attrs)
joined = " ".join(starmap("{}={!r}".format, attrs))
return f"<Odds {joined}>"
2 changes: 1 addition & 1 deletion neofoodclub/odds_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def arena(self) -> str:
def __repr__(self) -> str:
return f"<OddsChange arena={self.arena_index!r} index={self.index!r} pirate={self.pirate!r} old={self.old!r} new={self.new!r} timestamp={self.timestamp!r}>"

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__) and self._data == other.data

def __iter__(self) -> Iterator[tuple[str, Any]]:
Expand Down
5 changes: 3 additions & 2 deletions neofoodclub/pirates.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from itertools import starmap
from typing import TYPE_CHECKING, Any

from . import math
Expand Down Expand Up @@ -223,7 +224,7 @@ def won(self) -> bool:
def __int__(self) -> int:
return self._bin

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__) and int(self) == int(other)

def __repr__(self) -> str:
Expand All @@ -237,5 +238,5 @@ def __repr__(self) -> str:
("binary", self.binary),
("won", self.won),
]
joined = " ".join("{}={!r}".format(*t) for t in attrs)
joined = " ".join(starmap("{}={!r}".format, attrs))
return f"<Pirate {joined}>"
6 changes: 2 additions & 4 deletions neofoodclub/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ def make_line(row: Sequence[str]) -> str:
lines: list[str] = [line]
if _headers:
# add the headers, and a separator line
lines.append(make_line(_headers))
lines.append(line)
lines.extend((make_line(_headers), line))

for row in _rows:
lines.append(make_line(row))

if _footers:
lines.append(line)
lines.append(make_line(_footers))
lines.extend((line, make_line(_footers)))

lines.append(line)
return "\n".join(lines)
Expand Down
Loading

0 comments on commit 3f8e65b

Please sign in to comment.