Skip to content

Commit 276dc6e

Browse files
committed
style: Better typing for discord.Object
Signed-off-by: Mathieu Corsham <McCuber04@outlook.de>
1 parent 7cc41fd commit 276dc6e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

discord/object.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@
2727
from __future__ import annotations
2828

2929
from typing import (
30+
Any,
3031
Type,
3132
Optional,
3233
TYPE_CHECKING
3334
)
3435

3536
if TYPE_CHECKING:
37+
from .abc import Snowflake
3638
from datetime import datetime
3739
from .state import ConnectionState
3840

@@ -41,8 +43,13 @@
4143

4244
from . import utils
4345
from .mixins import Hashable
46+
4447
MISSING = utils.MISSING
4548

49+
__all__ = (
50+
'Object',
51+
)
52+
4653

4754
class Object(Hashable):
4855
"""Represents a generic Discord object.
@@ -79,11 +86,12 @@ class Object(Hashable):
7986
type: :class:`object`
8087
The object this should represent if any.
8188
"""
89+
id: int
8290

8391
def __init__(
8492
self,
8593
id: SnowflakeID,
86-
type: Type = utils.MISSING,
94+
type: Type = MISSING,
8795
*,
8896
state: Optional[ConnectionState] = MISSING
8997
):
@@ -98,7 +106,7 @@ def __init__(
98106
def __repr__(self) -> str:
99107
return f'<Object id={self.id!r} type={self.type!r}>'
100108

101-
def __instancecheck__(self, other) -> bool:
109+
def __instancecheck__(self, other: Any) -> bool:
102110
if self.type is not MISSING:
103111
return self.type == type(other)
104112
return self.__class__ == type(other)
@@ -107,3 +115,8 @@ def __instancecheck__(self, other) -> bool:
107115
def created_at(self) -> datetime:
108116
""":class:`datetime.datetime`: Returns the snowflake's creation time in UTC."""
109117
return utils.snowflake_time(self.id)
118+
119+
120+
if TYPE_CHECKING:
121+
class Object(Snowflake, Object):
122+
pass

0 commit comments

Comments
 (0)