def __len__(self): assert self._length in {None, 'parent'} or isinstance( self._length, int) if self._length is None and \ not is_method_redefined('__iter__', Transform, self) \ or self._length == 'parent': self._length = len(self._extractor) return super().__len__()
def categories(self) -> CategoriesInfo: if self.is_cache_initialized(): return self._categories elif self._categories is not None: return self._categories elif any( is_method_redefined('categories', Transform, t[0]) for t in self._transforms): self.init_cache() return self._categories else: return self._source.categories()
def transform(self, method: Type[Transform], *args, **kwargs): # Flush accumulated changes if not self._storage.is_empty(): source = self._merged() self._storage = DatasetItemStorage() else: source = self._source if not self._transforms: # The stack of transforms only needs a single source self._source = source self._transforms.append((method, args, kwargs)) if is_method_redefined('categories', Transform, method): self._categories = None self._length = None
def test_can_detect_changes_in_patched_instance(self): obj = self.Base() with mock.patch.object(obj, 'method'): self.assertTrue(is_method_redefined('method', self.Base, obj))
def test_can_detect_changes_in_derived_instance(self): class Derived(self.Base): def method(self): pass self.assertTrue(is_method_redefined('method', self.Base, Derived()))
def test_can_detect_no_changes_in_derived_class(self): class Derived(self.Base): pass self.assertFalse(is_method_redefined('method', self.Base, Derived))