Browse Source

Typehint mixins

pull/6987/head
Rapptz 4 years ago
parent
commit
5a9cbc967b
  1. 12
      discord/mixins.py

12
discord/mixins.py

@ -22,18 +22,24 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
""" """
from typing import TypeVar
__all__ = ( __all__ = (
'EqualityComparable', 'EqualityComparable',
'Hashable', 'Hashable',
) )
E = TypeVar('E', bound='EqualityComparable')
class EqualityComparable: class EqualityComparable:
__slots__ = () __slots__ = ()
def __eq__(self, other): id: int
def __eq__(self: E, other: E) -> bool:
return isinstance(other, self.__class__) and other.id == self.id return isinstance(other, self.__class__) and other.id == self.id
def __ne__(self, other): def __ne__(self: E, other: E) -> bool:
if isinstance(other, self.__class__): if isinstance(other, self.__class__):
return other.id != self.id return other.id != self.id
return True return True
@ -41,5 +47,5 @@ class EqualityComparable:
class Hashable(EqualityComparable): class Hashable(EqualityComparable):
__slots__ = () __slots__ = ()
def __hash__(self): def __hash__(self) -> int:
return self.id >> 22 return self.id >> 22

Loading…
Cancel
Save