Skip to content

Commit

Permalink
Add SubClasses registration to BaseEntity (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeMyst committed Apr 23, 2023
1 parent 63dac0c commit f265520
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion wikibaseintegrator/entities/baseentity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
from copy import copy
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type, Union

from wikibaseintegrator import wbi_fastrun
from wikibaseintegrator.datatypes import BaseDataType
Expand All @@ -20,6 +20,7 @@

class BaseEntity:
ETYPE = 'base-entity'
subclasses: List[Type[BaseDataType]] = []

def __init__(self, api: Optional['WikibaseIntegrator'] = None, title: Optional[str] = None, pageid: Optional[int] = None, lastrevid: Optional[int] = None,
type: Optional[str] = None, id: Optional[str] = None, claims: Optional[Claims] = None, is_bot: Optional[bool] = None, login: Optional[_Login] = None):
Expand All @@ -39,6 +40,11 @@ def __init__(self, api: Optional['WikibaseIntegrator'] = None, title: Optional[s
self.id = id
self.claims = claims or Claims()

# Allow registration of subclasses of BaseEntity into BaseEntity.subclasses
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
cls.subclasses.append(cls)

@property
def api(self) -> WikibaseIntegrator:
return self.__api
Expand Down

0 comments on commit f265520

Please sign in to comment.