class A:
	def __init__(self, s):
		self.s = s
	def __eq__(self, other):
		return self.s == other.s
print(A("string") == A("string")) # True
print(A("string") is A("string")) # False

class B(A):
	pool = {} # вообще это должен быть WeakValueDictionary,
	          # иначе пул будет препятствовать уничтожению объектов GC
	def __new__(cls, s):
		existing = B.pool.get(s, None)
		if existing: return existing
		result = super().__new__(cls)
		B.pool[s] = result
		return result
print(B("string") == B("string")) # True
print(B("string") is B("string")) # True