Skip to content

Commit

Permalink
Fix Item class issues
Browse files Browse the repository at this point in the history
Fixes #405
  • Loading branch information
Gobot1234 committed Dec 22, 2023
1 parent 4c3644d commit 76164e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
25 changes: 17 additions & 8 deletions steam/ext/csgo/backpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ def __repr__(self) -> str:
return f"<{self.__class__.__name__} id={self.id} position={self.position}>"


class CasketItem(BaseItem):
@BaseItem.register
class CasketItem(BaseItem if TYPE_CHECKING else object):
"""Represents an item in a :class:`Casket`."""

__slots__ = ("_casket_id",)
__slots__ = (*BaseItem.SLOTS, "_casket_id")
_casket_id: AssetID

@property
Expand All @@ -162,10 +163,8 @@ def __repr__(self) -> str:
return f"<{self.__class__.__name__} id={self.id} casket={self.casket}>"


@dataclass(repr=False)
class BaseInspectedItem:
"""Represents an item received after inspecting an item."""

@dataclass
class _BaseInspectedItem(metaclass=ABCMeta):
__slots__ = SLOTS = (
"id",
"def_index",
Expand Down Expand Up @@ -221,11 +220,21 @@ def __repr__(self) -> str:
return f"<{self.__class__.__name__} id={self.id}>"


@dataclass(repr=False)
@_BaseInspectedItem.register
class BaseInspectedItem(_BaseInspectedItem if TYPE_CHECKING else object, metaclass=ABCMeta):
"""Represents an item received after inspecting an item."""

__slots__ = _BaseInspectedItem.SLOTS
__annotations__ = _BaseInspectedItem.__annotations__


OwnerT = TypeVar("OwnerT", bound="PartialUser", default="BaseUser", covariant=True)


class InspectedItem(Item[OwnerT], BaseInspectedItem):
__slots__ = BaseInspectedItem.SLOTS
@BaseInspectedItem.register
class InspectedItem(Item[OwnerT], _BaseInspectedItem):
__slots__ = _BaseInspectedItem.SLOTS


F = TypeVar("F", bound=Callable[..., object])
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/test_ext_csgo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
from unittest.mock import MagicMock

from steam.ext import csgo
from steam.protobufs.econ import Asset, ItemDescription

client = csgo.Client()
bot = csgo.Bot(command_prefix="!")


def test_item_construction():
item = csgo.BackpackItem(MagicMock(), Asset(), ItemDescription(), MagicMock())
assert csgo.BackpackItem.__slots__
for attr in csgo.BackpackItem.__slots__:
setattr(item, attr, MagicMock())
csgo.BaseInspectedItem(*(MagicMock(),) * len(csgo.BaseInspectedItem.__slots__))
for attr in csgo.CasketItem.__slots__:
setattr(csgo.CasketItem(), attr, MagicMock())

0 comments on commit 76164e4

Please sign in to comment.