pickleable.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # testing/pickleable.py
  2. # Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
  3. # <see AUTHORS file>
  4. #
  5. # This module is part of SQLAlchemy and is released under
  6. # the MIT License: https://www.opensource.org/licenses/mit-license.php
  7. # mypy: ignore-errors
  8. """Classes used in pickling tests, need to be at the module level for
  9. unpickling.
  10. """
  11. from __future__ import annotations
  12. from .entities import ComparableEntity
  13. from ..schema import Column
  14. from ..types import String
  15. class User(ComparableEntity):
  16. pass
  17. class Order(ComparableEntity):
  18. pass
  19. class Dingaling(ComparableEntity):
  20. pass
  21. class EmailUser(User):
  22. pass
  23. class Address(ComparableEntity):
  24. pass
  25. # TODO: these are kind of arbitrary....
  26. class Child1(ComparableEntity):
  27. pass
  28. class Child2(ComparableEntity):
  29. pass
  30. class Parent(ComparableEntity):
  31. pass
  32. class Screen:
  33. def __init__(self, obj, parent=None):
  34. self.obj = obj
  35. self.parent = parent
  36. class Mixin:
  37. email_address = Column(String)
  38. class AddressWMixin(Mixin, ComparableEntity):
  39. pass
  40. class Foo:
  41. def __init__(self, moredata, stuff="im stuff"):
  42. self.data = "im data"
  43. self.stuff = stuff
  44. self.moredata = moredata
  45. __hash__ = object.__hash__
  46. def __eq__(self, other):
  47. return (
  48. other.data == self.data
  49. and other.stuff == self.stuff
  50. and other.moredata == self.moredata
  51. )
  52. class Bar:
  53. def __init__(self, x, y):
  54. self.x = x
  55. self.y = y
  56. __hash__ = object.__hash__
  57. def __eq__(self, other):
  58. return (
  59. other.__class__ is self.__class__
  60. and other.x == self.x
  61. and other.y == self.y
  62. )
  63. def __str__(self):
  64. return "Bar(%d, %d)" % (self.x, self.y)
  65. class OldSchool:
  66. def __init__(self, x, y):
  67. self.x = x
  68. self.y = y
  69. def __eq__(self, other):
  70. return (
  71. other.__class__ is self.__class__
  72. and other.x == self.x
  73. and other.y == self.y
  74. )
  75. class OldSchoolWithoutCompare:
  76. def __init__(self, x, y):
  77. self.x = x
  78. self.y = y
  79. class BarWithoutCompare:
  80. def __init__(self, x, y):
  81. self.x = x
  82. self.y = y
  83. def __str__(self):
  84. return "Bar(%d, %d)" % (self.x, self.y)
  85. class NotComparable:
  86. def __init__(self, data):
  87. self.data = data
  88. def __hash__(self):
  89. return id(self)
  90. def __eq__(self, other):
  91. return NotImplemented
  92. def __ne__(self, other):
  93. return NotImplemented
  94. class BrokenComparable:
  95. def __init__(self, data):
  96. self.data = data
  97. def __hash__(self):
  98. return id(self)
  99. def __eq__(self, other):
  100. raise NotImplementedError
  101. def __ne__(self, other):
  102. raise NotImplementedError