| 238 | self.on_remove() |
| 239 | |
| 240 | def add_item(self, item: Type[Any]) -> None: |
| 241 | # protect against class registration race condition against |
| 242 | # asynchronous garbage collection calling _remove_item, |
| 243 | # [ticket:3208] and [ticket:10782] |
| 244 | modules = { |
| 245 | cls.__module__ |
| 246 | for cls in [ref() for ref in list(self.contents)] |
| 247 | if cls is not None |
| 248 | } |
| 249 | if item.__module__ in modules: |
| 250 | util.warn( |
| 251 | "This declarative base already contains a class with the " |
| 252 | "same class name and module name as %s.%s, and will " |
| 253 | "be replaced in the string-lookup table." |
| 254 | % (item.__module__, item.__name__) |
| 255 | ) |
| 256 | self.contents.add(weakref.ref(item, self._remove_item)) |
| 257 | |
| 258 | |
| 259 | class _ModuleMarker(_ClsRegistryToken): |