Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type annotations with using type.List. #90

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading