Skip to content

Commit 9059166

Browse files
authored
Merge pull request #205 from zero-sum-seattle/issue#204_fix
Adds Violation Class to PlayDetails. Fixes Issue #204
2 parents c65db52 + 8288db8 commit 9059166

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

mlbstatsapi/models/data/data.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,22 @@ class CodeDesc:
233233
code: str
234234
description: Optional[str] = None
235235

236+
@dataclass
237+
class Violation:
238+
"""
239+
240+
Attributes
241+
----------
242+
type : str
243+
the type of violation during the play
244+
description : str
245+
the description of the violation that occured
246+
player : player
247+
the player that caused the violation
248+
"""
249+
type: Optional[str] = None
250+
description: Optional[str] = None
251+
player: Optional[dict] = None
236252

237253
@dataclass(repr=False)
238254
class Count:
@@ -332,12 +348,14 @@ class PlayDetails:
332348
trailcolor: Optional[str] = None
333349
fromcatcher: Optional[bool] = None
334350
disengagementnum: Optional[int] = None
351+
violation: Optional[Union[Violation, dict]] = field(default_factory=dict)
335352

336353
def __post_init__(self):
337354
self.call = CodeDesc(**self.call) if self.call else self.call
338355
self.batside = CodeDesc(**self.batside) if self.batside else self.batside
339356
self.pitchhand = CodeDesc(**self.pitchhand) if self.pitchhand else self.pitchhand
340357
self.type = CodeDesc(**self.type) if self.type else self.type
358+
self.violation = Violation(**self.violation) if self.violation else self.violation
341359

342360
def __repr__(self) -> str:
343361
kws = [f'{key}={value}' for key, value in self.__dict__.items() if value is not None and value]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "python-mlb-statsapi"
7-
version = "0.5.16"
7+
version = "0.5.17"
88

99
authors = [
1010
{ name="Matthew Spah", email="spahmatthew@gmail.com" },

tests/external_tests/game/test_game.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ class TestGame(unittest.TestCase):
1515
@classmethod
1616
def setUpClass(cls) -> None:
1717
cls.mlb = Mlb()
18-
cls.game = cls.mlb.get_game(662242)
18+
cls.game = cls.mlb.get_game(717911)
1919

2020
@classmethod
2121
def tearDownClass(cls) -> None:
2222
pass
2323

2424
def test_game_creation(self):
25-
self.assertEqual(self.game.id, 662242)
25+
self.assertEqual(self.game.id, 717911)
2626
self.assertIsInstance(self.game, Game)
2727

2828
def test_game_attrs(self):

0 commit comments

Comments
 (0)