Skip to content

Commit 924a923

Browse files
authored
DevContainer Fix/Updates & Backwards Compatiblity Support for EventMsgType 'UNKNOWN/INSTANT_REPLAY' (#402)
* updated regular expression for team turnover to account for no space T# 12 --> T#12 * Debian 12 (latest) broke DevContainers using the Python feature. Flake8 has been deprecated as a setting in settings.json. * Updated devcontainer extensions * updated postCreateCommand.sh to install the root project * Added deprecation warning for UNKNOWN within eventmsgtype along with included test.
1 parent a33c1ac commit 924a923

File tree

6 files changed

+79
-9
lines changed

6 files changed

+79
-9
lines changed

.devcontainer/devcontainer.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"ghcr.io/devcontainers/features/python:latest": {},
77
"ghcr.io/devcontainers-contrib/features/poetry:2": {}
88
},
9-
"image": "mcr.microsoft.com/devcontainers/base:debian",
9+
"image": "mcr.microsoft.com/devcontainers/base:debian-11",
1010
"name": "nba_api",
1111
"postCreateCommand": "bash .devcontainer/postCreateCommand.sh",
1212
"remoteEnv": {
@@ -15,12 +15,14 @@
1515
"customizations": {
1616
"vscode": {
1717
"extensions": [
18-
"ms-python.python",
19-
"ms-toolsai.jupyter-keymap",
2018
"ms-python.black-formatter",
19+
"ms-python.flake8",
20+
"ms-python.python",
21+
"ms-python.vscode-pylance",
2122
"ms-toolsai.jupyter",
22-
"ms-toolsai.vscode-jupyter-powertoys",
23-
"ms-toolsai.jupyter-renderers"
23+
"ms-toolsai.jupyter-keymap",
24+
"ms-toolsai.jupyter-renderers",
25+
"ms-toolsai.vscode-jupyter-powertoys"
2426
]
2527
}
2628
}

.devcontainer/postCreateCommand.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pip install --upgrade pip
2-
poetry install --no-root
2+
poetry install
33

44
# Activate poetry environment
55
source $(poetry env info --path)/bin/activate

.vscode/settings.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"editor.formatOnSave": true,
3-
"python.linting.flake8Enabled": true,
3+
"flake8.args": [
4+
"--config=.flake8"
5+
],
46
"python.formatting.provider": "black",
57
"python.formatting.blackArgs": [
68
"--line-length",

src/nba_api/library/_enum_base.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from enum import Enum, EnumMeta
2+
3+
4+
class OnAccess(EnumMeta):
5+
"""
6+
runs a user-specified function whenever member is accessed
7+
"""
8+
9+
def __getattribute__(cls, name):
10+
obj = super().__getattribute__(name)
11+
if isinstance(obj, Enum) and obj._on_access:
12+
obj._on_access()
13+
return obj
14+
15+
def __getitem__(cls, name):
16+
member = super().__getitem__(name)
17+
if member._on_access:
18+
member._on_access()
19+
return member
20+
21+
def __call__(
22+
cls, value, names=None, *, module=None, qualname=None, type=None, start=1
23+
):
24+
obj = super().__call__(
25+
value, names, module=module, qualname=qualname, type=type, start=start
26+
)
27+
if isinstance(obj, Enum) and obj._on_access:
28+
obj._on_access()
29+
return obj
30+
31+
32+
class DeprecatedEnum(Enum, metaclass=OnAccess):
33+
def __new__(cls, value, *args):
34+
member = object.__new__(cls)
35+
member._value_ = value
36+
member._args = args
37+
member._on_access = member.deprecate if args else None
38+
return member
39+
40+
def deprecate(self):
41+
args = self._args
42+
import warnings
43+
44+
warnings.warn(
45+
"%s" % args,
46+
DeprecationWarning,
47+
stacklevel=3,
48+
)

src/nba_api/stats/library/eventmsgtype.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from enum import Enum
1+
from nba_api.library._enum_base import DeprecatedEnum
22

33

4-
class EventMsgType(Enum):
4+
class EventMsgType(DeprecatedEnum):
55
FIELD_GOAL_MADE = 1
66
FIELD_GOAL_MISSED = 2
77
FREE_THROW = 3
@@ -15,4 +15,6 @@ class EventMsgType(Enum):
1515
EJECTION = 11
1616
PERIOD_BEGIN = 12
1717
PERIOD_END = 13
18+
# Deprecated as of 2023.11.10
19+
UNKNOWN = 18, "'UNKNOWN' member is deprecated; use 'INSTANT_REPLAY' instead."
1820
INSTANT_REPLAY = 18

tests/unit/test_eventmsgtype.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import warnings
2+
from nba_api.stats.library.eventmsgtype import EventMsgType
3+
4+
5+
def test_eventmsgtype():
6+
with warnings.catch_warnings(record=True) as w:
7+
# Invoke Deprecation Warning
8+
_ = EventMsgType.UNKNOWN
9+
10+
assert len(w) == 1
11+
12+
assert issubclass(w[0].category, DeprecationWarning)
13+
assert (
14+
str(w[0].message)
15+
== "'UNKNOWN' member is deprecated; use 'INSTANT_REPLAY' instead."
16+
)

0 commit comments

Comments
 (0)