matej_suchanek updated the task description. (Show Details)

CHANGES TO TASK DESCRIPTION
Currently, data of claims, qualifiers and references are held in a single class, `pywikibot.Claim`. I propose to factor things common for all of them to a new class `pywikibot.BaseClaim` and introduce new classes `pywikibot.Qualifier`, `pywikibot.Reference` and `pywikibot.ReferenceGroup` that would inherit from the base class.

This will have many advantages:

- fixing T186198 will be easier
- input validation (eg. in `site.py`) will only require `assert isinstance()`
- `pywikibot.Qualifier(repo, 'P123')` is simpler and less confusing than `pywikibot.Claim(repo, 'P123', isQualifier=True)`

Problem: backwards compatibility.
Currently, data of claims, qualifiers and references are held in a single class, `pywikibot.Claim`. I propose to factor things common for all of them to a new class `pywikibot.BaseClaim` and introduce new classes `pywikibot.Qualifier`, `pywikibot.Reference` and `pywikibot.ReferenceGroup`. All but `pywikibot.ReferenceGroup` would inherit from the base class.

This will have many advantages:

- fixing T186198 will be easier
- input validation (eg. in `site.py`) will only require `assert isinstance()`
- `pywikibot.Qualifier(repo, 'P123')` is simpler and less confusing than `pywikibot.Claim(repo, 'P123', isQualifier=True)`

Problem: backwards compatibility.

= Current framework =
```lang=python
class Claim(Property):

'''Class variables'''
TARGET_CONVERTER = {}
SNAK_TYPES = ()

def __init__():
'''Attributes'''
self.snak = snak
self.hash = hash
self.isReference = isReference
self.isQualifier = isQualifier
self.sources = []
self.qualifiers = OrderedDict()
self.target = None
self.snaktype = 'value'
self.rank = 'normal'
self._on_item_ = None

'''Methods'''
def __repr__
def fromJSON
def referenceFromJSON
def qualifierFromJSON
def toJSON
def setTarget
def changeTarget
def getTarget
def getSnakType
def setSnakType
def getRank
def setRank
def changeRank
def changeSnakType
def getSources
def addSource
def addSources
def removeSource
def removeSources
def addQualifier
def removeQualifier
def removeQualifiers
def target_equals
def has_qualifier
def _formatValue
def _formatDataValue
```

= Proposed frameword =
```lang=python
class BaseClaim(Property):

'''Class variables'''
TARGET_CONVERTER = {}
SNAK_TYPES = ()

def __init__():
'''Attributes'''
self.target = None
self.snaktype = 'value'

'''Methods'''
def __repr__(self): raise NotImplementedError
def fromJSON(self): raise NotImplementedError
def toJSON(self): raise NotImplementedError
def changeTarget(self): raise NotImplementedError
def changeSnakType(self): raise NotImplementedError
def target_equals
def setTarget
def getTarget
def getSnakType
def setSnakType
def _formatValue
def _formatDataValue

class Claim(BaseClaim):

def __init__():
'''Attributes'''
self.rank = 'normal'
self.qualifiers = OrderedDict()
self.references = []

def getRank
def setRank
def changeRank
def getSources
def addSource
def addSources
def removeSource
def removeSources
def addQualifier
def removeQualifier
def removeQualifiers
def has_qualifier

class Qualifier(BaseClaim):

def __init__():
'''Attributes'''
self.parent = None

def __repr__
def fromJSON
def toJSON
def changeTarget
def changeSnakType

class ReferenceGroup(object):

def __init__():
'''Attributes'''
self.parent = None
self.references = OrderedDict()

def toJSON
def fromJSON

class Reference(BaseClaim):

def __init__():
'''Attributes'''
self.parent = None

def __repr__
def fromJSON
def toJSON
def changeTarget
def changeSnakType
```

TASK DETAIL
https://phabricator.wikimedia.org/T186200

EMAIL PREFERENCES
https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: matej_suchanek
Cc: Aklapper, matej_suchanek, pywikibot-bugs-list, Magul, Tbscho, rafidaslam, MayS, Framawiki, Mdupont, JJMC89, Avicennasis, jayvdb, Ricordisamoa, Dalba, Masti, Alchimista, Rxy
_______________________________________________
pywikibot-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-bugs

Reply via email to