Skip to content

Commit

Permalink
Fix type annotations with using type.List. (#90)
Browse files Browse the repository at this point in the history
* Fix type annotations with using `type.List`.

* Deprecate Python 3.7

See: https://devguide.python.org/versions/
  • Loading branch information
azriel1rf authored Apr 29, 2024
1 parent 835226b commit bf1a1dd
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.x
Expand Down
5 changes: 3 additions & 2 deletions python/phevaluator/evaluator_omaha.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Module evaluating cards in Omaha game."""

from __future__ import annotations

from typing import Union
from typing import List, Union

from .card import Card
from .hash import hash_binary, hash_quinary
Expand Down Expand Up @@ -51,7 +52,7 @@ def evaluate_omaha_cards(*cards: Union[int, str, Card]) -> int:
return _evaluate_omaha_cards(community_cards, hole_cards)


def _evaluate_omaha_cards(community_cards: [int], hole_cards: [int]) -> int:
def _evaluate_omaha_cards(community_cards: List[int], hole_cards: List[int]) -> int:
value_flush = 10000
value_noflush = 10000
suit_count_board = [0] * 4
Expand Down
7 changes: 5 additions & 2 deletions python/phevaluator/hash.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
"""Module hashing cards."""

from __future__ import annotations

from typing import List

from .tables import CHOOSE, DP


def hash_quinary(quinary: [int], num_cards: int) -> int:
def hash_quinary(quinary: List[int], num_cards: int) -> int:
"""Hash list of cards.
Args:
quinary ([int]): List of the count of the cards.
quinary (List[int]): List of the count of the cards.
num_cards (int): The number of cards.
Returns:
Expand Down
13 changes: 11 additions & 2 deletions python/phevaluator/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
"""Utilities."""

from __future__ import annotations

import random
from typing import List


def sample_cards(size: int) -> List[int]:
"""Sample random cards with size.
Args:
size (int): The size of the sample.
def sample_cards(size: int) -> [int]:
"""Sample random cards with size."""
Returns:
List[int]: The list of the sampled cards.
"""
return random.sample(range(52), k=size)
3 changes: 1 addition & 2 deletions python/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ classifiers =
License :: OSI Approved :: Apache Software License
Topic :: Software Development :: Libraries
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Expand All @@ -32,7 +31,7 @@ project_urls =
Source = https://github.com/HenryRLee/PokerHandEvaluator/tree/master/python

[options]
python_requires= >=3.7, <4
python_requires= >=3.8, <4
packages = find:
install_requires =
numpy
Expand Down
5 changes: 3 additions & 2 deletions python/tests/table_tests/test_hashtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import unittest
from itertools import combinations
from typing import List

from phevaluator.tables import FLUSH

Expand All @@ -11,8 +12,8 @@ class TestFlushTable(unittest.TestCase):
VISIT = [0] * len(FLUSH)
CUR_RANK = 1

CACHE: [int] = []
BINARIES: [int] = []
CACHE: List[int] = []
BINARIES: List[List[int]] = []

@classmethod
def setUpClass(cls):
Expand Down
5 changes: 3 additions & 2 deletions python/tests/table_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import unittest
from itertools import combinations, combinations_with_replacement, permutations
from typing import List

from phevaluator.hash import hash_quinary
from phevaluator.tables import NO_FLUSH_5


class BaseTestNoFlushTable(unittest.TestCase):
TABLE: [int] = NotImplemented
VISIT: [int] = NotImplemented
TABLE: List[int] = NotImplemented
VISIT: List[int] = NotImplemented
NUM_CARDS: int = NotImplemented

@classmethod
Expand Down
3 changes: 2 additions & 1 deletion python/tests/test_evalator_omaha.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import unittest
from itertools import combinations
from typing import List

from phevaluator import (
Card,
Expand All @@ -12,7 +13,7 @@
)


def evaluate_omaha_exhaustive(community_cards: [int], hole_cards: [int]) -> int:
def evaluate_omaha_exhaustive(community_cards: List[int], hole_cards: List[int]) -> int:
"""Evaluate omaha cards with `_evaluate_cards`."""
best_rank = min(
_evaluate_cards(c1, c2, c3, h1, h2)
Expand Down

0 comments on commit bf1a1dd

Please sign in to comment.