Skip to content

Commit

Permalink
UPDATE: deprecate dict method
Browse files Browse the repository at this point in the history
Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com>
  • Loading branch information
Segelzwerg committed Jul 21, 2023
1 parent 538c67a commit d19229e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
56 changes: 50 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ classifiers = [
[tool.poetry.dependencies]
python = "^3.9"
pydantic = ">=1.10,<3.0"
deprecation = "^2.1.0"

[tool.poetry.dev-dependencies]
pytest = "^7.4"
Expand Down
14 changes: 13 additions & 1 deletion whist_core/game/hand.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Hand of whist"""
from typing import Optional
from typing import Optional, Any, Dict

import deprecation
from pydantic import BaseModel

from whist_core.cards.card import Card, Suit
Expand Down Expand Up @@ -73,11 +74,22 @@ def next_trick(self, play_order: PlayOrder) -> Trick:
self.tricks.append(next_trick)
return next_trick

@deprecation.deprecated("Use 'model_dump()' instead")
def dict(self, *args, **kwargs):
"""Returns as dictionary."""
super_dict = super().dict(*args, **kwargs)
return enforce_str_on_dict(super_dict, ['trump'])

def model_dump(self, *, mode: str = 'python', include=None,
exclude=None, by_alias: bool = False, exclude_unset: bool = False,
exclude_defaults: bool = False, exclude_none: bool = False,
round_trip: bool = False, warnings: bool = True) -> Dict[str, Any]:
model = super().model_dump(mode=mode, include=include, exclude=exclude, by_alias=by_alias,

Check warning on line 87 in whist_core/game/hand.py

View check run for this annotation

Codecov / codecov/patch

whist_core/game/hand.py#L87

Added line #L87 was not covered by tests
exclude_unset=exclude_unset, exclude_defaults=exclude_defaults,
exclude_none=exclude_none, round_trip=round_trip,
warnings=warnings)
return enforce_str_on_dict(model, ['trump'])

Check warning on line 91 in whist_core/game/hand.py

View check run for this annotation

Codecov / codecov/patch

whist_core/game/hand.py#L91

Added line #L91 was not covered by tests

def _winner_plays_first_card(self, play_order: PlayOrder) -> PlayOrder:
winner: PlayerAtTable = self.tricks[-1].winner
return play_order.rotate(winner)

0 comments on commit d19229e

Please sign in to comment.