Hashar has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/145678

Change subject: Pass pep257 on some of the files
......................................................................

Pass pep257 on some of the files

Using flake8-docstrings.  The files are not 100% compliant.

Change-Id: I03f9cf80cea01823da332ddf6c3e0d23633cc21d
---
M pywikibot/__init__.py
M pywikibot/bot.py
M pywikibot/exceptions.py
3 files changed, 66 insertions(+), 53 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/78/145678/1

diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 83093f5..ccf5e37 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -64,7 +64,7 @@
         return cls.strptime(ts, cls.mediawikiTSFormat)
 
     def toISOformat(self):
-        """Convert the Timestamp object to an ISO 8601 timestamp"""
+        """Convert the Timestamp object to an ISO 8601 timestamp."""
         return self.strftime(self.ISO8601Format)
 
     def totimestampformat(self):
@@ -72,7 +72,7 @@
         return self.strftime(self.mediawikiTSFormat)
 
     def __str__(self):
-        """Return a string format recognized by the API"""
+        """Return a string format recognized by the API."""
         return self.toISOformat()
 
     def __add__(self, other):
@@ -98,12 +98,16 @@
 
     """
     Class for handling and storing Coordinates.
+
     For now its just being used for DataSite, but
     in the future we can use it for the GeoData extension.
     """
+
     def __init__(self, lat, lon, alt=None, precision=None, globe='earth',
                  typ="", name="", dim=None, site=None, entity=''):
         """
+        Represent a geo coordinate.
+
         @param lat: Latitude
         @type lat: float
         @param lon: Longitute
@@ -153,8 +157,8 @@
 
     def toWikibase(self):
         """
-        Function which converts the data to a JSON object
-        for the Wikibase API.
+        Function which converts the data to a JSON object for the Wikibase API.
+
         FIXME Should this be in the DataSite object?
         """
         if self.globe not in self.site.globes():
@@ -168,7 +172,7 @@
 
     @staticmethod
     def fromWikibase(data, site):
-        """Constructor to create an object from Wikibase's JSON output"""
+        """Constructor to create an object from Wikibase's JSON output."""
         globes = {}
         for k in site.globes():
             globes[site.globes()[k]] = k
@@ -206,7 +210,7 @@
         return self._precision
 
     def precisionToDim(self):
-        """Convert precision from Wikibase to GeoData's dim"""
+        """Convert precision from Wikibase to GeoData's dim."""
         raise NotImplementedError
 
 
@@ -220,9 +224,10 @@
     def __init__(self, year=None, month=None, day=None, hour=None, 
minute=None, second=None, precision=None, before=0,
                  after=0, timezone=0, calendarmodel=None, site=None):
         """
-        Creates a new WbTime object. The precision can be set
-        by the Wikibase int value (0-14) or by a human readable
-        string, e.g., 'hour'. If no precision is given, it is set
+        Create a new WbTime object.
+
+        The precision can be set by the Wikibase int value (0-14) or by a human
+        readable string, e.g., 'hour'. If no precision is given, it is set
         according to the given time units.
         """
         if year is None:
@@ -279,15 +284,14 @@
 
     def toTimestr(self):
         """
-        Function which converts the the data to a UTC date/time string
+        Function which converts the the data to a UTC date/time string.
         """
         return self.FORMATSTR.format(self.year, self.month, self.day,
                                      self.hour, self.minute, self.second)
 
     def toWikibase(self):
         """
-        Function which converts the data to a JSON object
-        for the Wikibase API.
+        Function which converts the data to a JSON object for the Wikibase API.
         """
         json = {'time': self.toTimestr(),
                 'precision': self.precision,
@@ -318,16 +322,17 @@
 
 class WbQuantity(object):
 
-    """ A Wikibase quantity representation"""
+    """A Wikibase quantity representation."""
 
     def __init__(self, amount, unit=None, error=None):
-        """
-        Creates a new WbQuantity object. The amount is a number representing
-        this quantity. The unit is currently not used (only unit-less
-        quantities are supported). The error is a number indicating the
-        uncertainty of the amount (e.g. ±1). Alternatively the error can be
-        expressed as a tuple, where the first value is the upper error and the
-        second is the lower error value.
+        u"""
+        Create a new WbQuantity object.
+
+        The amount is a number representing this quantity. The unit is
+        currently not used (only unit-less quantities are supported). The error
+        is a number indicating the uncertainty of the amount (e.g. ±1).
+        Alternatively the error can be expressed as a tuple, where the first
+        value is the upper error and the second is the lower error value.
         """
         if amount is None:
             raise ValueError('no amount given')
@@ -347,8 +352,7 @@
 
     def toWikibase(self):
         """
-        Function which converts the data to a JSON object
-        for the Wikibase API.
+        Convert the data to a JSON object for the Wikibase API.
         """
         json = {'amount': self.amount,
                 'upperBound': self.upperBound,
@@ -398,7 +402,7 @@
 
 
 def deprecate_arg(old_arg, new_arg):
-    """Decorator to declare old_arg deprecated and replace it with new_arg"""
+    """Decorator to declare old_arg deprecated and replace it with new_arg."""
     _logger = ""
 
     def decorator(method):
@@ -503,9 +507,9 @@
 def showDiff(oldtext, newtext):
     """
     Output a string showing the differences between oldtext and newtext.
+
     The differences are highlighted (only on compatible systems) to show which
     changes were made.
-
     """
     # This is probably not portable to non-terminal interfaces....
     # For information on difflib, see http://pydoc.org/2.1/difflib.html
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index a98eba8..4220600 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -101,7 +101,7 @@
         self.stream = self._open()
 
     def format(self, record):
-        """Strip trailing newlines before outputting text to file"""
+        """Strip trailing newlines before outputting text to file."""
         text = logging.handlers.RotatingFileHandler.format(self, record)
         return text.rstrip("\r\n")
 
@@ -115,8 +115,11 @@
     whether the output to the user's console does.
 
     """
+
     def formatException(self, ei):
-        """
+        r"""
+        Convert exceptions trace to unicode.
+
         Make sure that the exception trace is converted to unicode:
             * our pywikibot.Error traces are encoded in our
               console encoding, which is needed for plainly printing them.
@@ -183,7 +186,6 @@
     Accordingly, do ''not'' use print statements in bot code; instead,
     use pywikibot.output function.
     """
-
     global _handlers_initialized
 
     moduleName = calledModuleName()
@@ -377,7 +379,7 @@
 
 
 def output(text, decoder=None, newline=True, toStdout=False, **kwargs):
-    """Output a message to the user via the userinterface.
+    r"""Output a message to the user via the userinterface.
 
     Works like print, but uses the encoding used by the user's console
     (console_encoding in the configuration file) instead of ASCII.
@@ -767,13 +769,13 @@
 
     def __init__(self, **kwargs):
         """
-        Only accepts options defined in availableOptions
+        Only accept options defined in availableOptions.
         """
         self.setOptions(**kwargs)
 
     def setOptions(self, **kwargs):
         """
-        Sets the instance options
+        Set the instance options.
         """
         # contains the options overriden from defaults
         self.options = {}
@@ -791,6 +793,7 @@
     def getOption(self, option):
         """
         Get the current value of an option.
+
         @param option: key defined in Bot.availableOptions
         """
         try:
@@ -838,14 +841,14 @@
 class WikidataBot:
 
     """
-    Generic Wikidata Bot to be subclassed
-    used in claimit.py, coordinate_import.py and harvest_template.py
+    Generic Wikidata Bot to be subclassed.
+
+    Used in claimit.py, coordinate_import.py and harvest_template.py
     """
 
     def cacheSources(self):
         """
-        Fetches the sources from the onwiki list
-        and stores it internally
+        Fetch the sources from the onwiki list and stores it internally.
         """
         page = pywikibot.Page(self.repo, u'List of wikis/python', ns=4)
         self.source_values = json.loads(page.get())
@@ -856,8 +859,7 @@
 
     def getSource(self, site):
         """
-        Get the source for the specified site,
-        if possible
+        Get the source for the specified site, if possible.
         """
         if site.family.name in self.source_values and site.code in 
self.source_values[site.family.name]:
             source = pywikibot.Claim(self.repo, 'P143')
diff --git a/pywikibot/exceptions.py b/pywikibot/exceptions.py
index b7a4fd5..459bc2a 100644
--- a/pywikibot/exceptions.py
+++ b/pywikibot/exceptions.py
@@ -18,7 +18,8 @@
 
 class Error(UnicodeMixin, Exception):
 
-    """Pywikibot error"""
+    """Pywikibot error."""
+
     # NOTE: UnicodeMixin must be the first object Error class is derived from.
     def __init__(self, arg):
         self.unicode = arg
@@ -52,68 +53,73 @@
 
 class NoUsername(Error):
 
-    """Username is not in user-config.py"""
+    """Username is not in user-config.py."""
 
 
 class NoPage(PageRelatedError):
 
-    """Page does not exist"""
+    """Page does not exist."""
+
     message = u"Page %s doesn't exist."
 
 
 class NoSuchSite(Error):
 
-    """Site does not exist"""
+    """Site does not exist."""
 
 
 class IsRedirectPage(PageRelatedError):
 
-    """Page is a redirect page"""
+    """Page is a redirect page."""
+
     message = u"Page %s is a redirect page."
 
 
 class IsNotRedirectPage(PageRelatedError):
 
-    """Page is not a redirect page"""
+    """Page is not a redirect page."""
+
     message = u"Page %s is not a redirect page."
 
 
 class CircularRedirect(PageRelatedError):
 
-    """Page is a circular redirect
+    """Page is a circular redirect.
 
     Exception argument is the redirect target; this may be the same title
     as this page or a different title (in which case the target page directly
     or indirectly redirects back to this one)
 
     """
+
     message = u"Page %s is a circular redirect."
 
 
 class InvalidTitle(Error):
 
-    """Invalid page title"""
+    """Invalid page title."""
 
 
 class LockedPage(PageRelatedError):
 
-    """Page is locked"""
+    """Page is locked."""
+
     message = u"Page %s is locked."
 
 
 class SectionError(Error):
 
-    """The section specified by # does not exist"""
+    """The section specified by # does not exist."""
 
 
 class PageNotSaved(Error):
 
-    """Saving the page has failed"""
+    """Saving the page has failed."""
 
 
 class EditConflict(PageNotSaved):
 
-    """There has been an edit conflict while uploading the page"""
+    """There has been an edit conflict while uploading the page."""
 
 
 class SpamfilterError(PageNotSaved):
@@ -121,6 +127,7 @@
     """Saving the page has failed because the MediaWiki spam filter detected a
     blacklisted URL.
     """
+
     def __init__(self, arg):
         super(SpamfilterError, self).__init__(
             u'MediaWiki spam filter has been triggered')
@@ -130,7 +137,7 @@
 
 class ServerError(Error):
 
-    """Got unexpected server response"""
+    """Got unexpected server response."""
 
 
 class FatalServerError(ServerError):
@@ -141,7 +148,7 @@
 
 class Server504Error(Error):
 
-    """Server timed out with http 504 code"""
+    """Server timed out with http 504 code."""
 
 
 class BadTitle(Error):
@@ -155,12 +162,12 @@
 
 class UserBlocked(Error):
 
-    """Your username or IP has been blocked"""
+    """Your username or IP has been blocked."""
 
 
 class PageNotFound(Error):
 
-    """Page not found in list"""
+    """Page not found in list."""
 
 
 class CaptchaError(Error):
@@ -192,4 +199,4 @@
 
 class CoordinateGlobeUnknownException(WikiBaseError, NotImplementedError):
 
-    """ This globe is not implemented yet in either WikiBase or pywikibot """
+    """ This globe is not implemented yet in either WikiBase or pywikibot."""

-- 
To view, visit https://gerrit.wikimedia.org/r/145678
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I03f9cf80cea01823da332ddf6c3e0d23633cc21d
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Hashar <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to