]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Some codestyle updates in babel.numbers
authorArmin Ronacher <armin.ronacher@active-4.com>
Thu, 25 Jul 2013 07:22:21 +0000 (09:22 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Thu, 25 Jul 2013 07:22:21 +0000 (09:22 +0200)
babel/numbers.py

index 8d159784462a90cc24566549efe38dddc6c95ab5..0f387190a7a2c697701d3b85f582813e4b03e8a0 100644 (file)
@@ -25,26 +25,22 @@ import re
 from babel.core import default_locale, Locale
 from babel._compat import range_type
 
-__all__ = ['format_number', 'format_decimal', 'format_currency',
-           'format_percent', 'format_scientific', 'parse_number',
-           'parse_decimal', 'NumberFormatError']
-
 
 LC_NUMERIC = default_locale('LC_NUMERIC')
 
+
 def get_currency_name(currency, count=None, locale=LC_NUMERIC):
     """Return the name used by the locale for the specified currency.
 
     >>> get_currency_name('USD', locale='en_US')
     u'US Dollar'
+    
+    .. versionadded:: 0.9.4
 
     :param currency: the currency code
     :param count: the optional count.  If provided the currency name
                   will be pluralized to that number if possible.
     :param locale: the `Locale` object or locale identifier
-    :return: the currency symbol
-    :rtype: `unicode`
-    :since: version 0.9.4
     """
     loc = Locale.parse(locale)
     if count is not None:
@@ -54,6 +50,7 @@ def get_currency_name(currency, count=None, locale=LC_NUMERIC):
             return plural_names[currency][plural_form]
     return loc.currencies.get(currency, currency)
 
+
 def get_currency_symbol(currency, locale=LC_NUMERIC):
     """Return the symbol used by the locale for the specified currency.
 
@@ -62,11 +59,10 @@ def get_currency_symbol(currency, locale=LC_NUMERIC):
 
     :param currency: the currency code
     :param locale: the `Locale` object or locale identifier
-    :return: the currency symbol
-    :rtype: `unicode`
     """
     return Locale.parse(locale).currency_symbols.get(currency, currency)
 
+
 def get_decimal_symbol(locale=LC_NUMERIC):
     """Return the symbol used by the locale to separate decimal fractions.
 
@@ -74,11 +70,10 @@ def get_decimal_symbol(locale=LC_NUMERIC):
     u'.'
 
     :param locale: the `Locale` object or locale identifier
-    :return: the decimal symbol
-    :rtype: `unicode`
     """
     return Locale.parse(locale).number_symbols.get('decimal', u'.')
 
+
 def get_plus_sign_symbol(locale=LC_NUMERIC):
     """Return the plus sign symbol used by the current locale.
 
@@ -86,11 +81,10 @@ def get_plus_sign_symbol(locale=LC_NUMERIC):
     u'+'
 
     :param locale: the `Locale` object or locale identifier
-    :return: the plus sign symbol
-    :rtype: `unicode`
     """
     return Locale.parse(locale).number_symbols.get('plusSign', u'+')
 
+
 def get_minus_sign_symbol(locale=LC_NUMERIC):
     """Return the plus sign symbol used by the current locale.
 
@@ -98,11 +92,10 @@ def get_minus_sign_symbol(locale=LC_NUMERIC):
     u'-'
 
     :param locale: the `Locale` object or locale identifier
-    :return: the plus sign symbol
-    :rtype: `unicode`
     """
     return Locale.parse(locale).number_symbols.get('minusSign', u'-')
 
+
 def get_exponential_symbol(locale=LC_NUMERIC):
     """Return the symbol used by the locale to separate mantissa and exponent.
 
@@ -110,11 +103,10 @@ def get_exponential_symbol(locale=LC_NUMERIC):
     u'E'
 
     :param locale: the `Locale` object or locale identifier
-    :return: the exponential symbol
-    :rtype: `unicode`
     """
     return Locale.parse(locale).number_symbols.get('exponential', u'E')
 
+
 def get_group_symbol(locale=LC_NUMERIC):
     """Return the symbol used by the locale to separate groups of thousands.
 
@@ -122,11 +114,10 @@ def get_group_symbol(locale=LC_NUMERIC):
     u','
 
     :param locale: the `Locale` object or locale identifier
-    :return: the group symbol
-    :rtype: `unicode`
     """
     return Locale.parse(locale).number_symbols.get('group', u',')
 
+
 def format_number(number, locale=LC_NUMERIC):
     u"""Return the given number formatted for a specific locale.
 
@@ -138,12 +129,11 @@ def format_number(number, locale=LC_NUMERIC):
 
     :param number: the number to format
     :param locale: the `Locale` object or locale identifier
-    :return: the formatted number
-    :rtype: `unicode`
     """
     # Do we really need this one?
     return format_decimal(number, locale=locale)
 
+
 def format_decimal(number, format=None, locale=LC_NUMERIC):
     u"""Return the given decimal number formatted for a specific locale.
 
@@ -167,8 +157,6 @@ def format_decimal(number, format=None, locale=LC_NUMERIC):
     :param number: the number to format
     :param format:
     :param locale: the `Locale` object or locale identifier
-    :return: the formatted decimal number
-    :rtype: `unicode`
     """
     locale = Locale.parse(locale)
     if not format:
@@ -176,6 +164,7 @@ def format_decimal(number, format=None, locale=LC_NUMERIC):
     pattern = parse_pattern(format)
     return pattern.apply(number, locale)
 
+
 def format_currency(number, currency, format=None, locale=LC_NUMERIC):
     u"""Return formatted currency value.
 
@@ -199,8 +188,6 @@ def format_currency(number, currency, format=None, locale=LC_NUMERIC):
     :param number: the number to format
     :param currency: the currency code
     :param locale: the `Locale` object or locale identifier
-    :return: the formatted currency value
-    :rtype: `unicode`
     """
     locale = Locale.parse(locale)
     if not format:
@@ -208,6 +195,7 @@ def format_currency(number, currency, format=None, locale=LC_NUMERIC):
     pattern = parse_pattern(format)
     return pattern.apply(number, locale, currency=currency)
 
+
 def format_percent(number, format=None, locale=LC_NUMERIC):
     """Return formatted percent value for a specific locale.
 
@@ -226,8 +214,6 @@ def format_percent(number, format=None, locale=LC_NUMERIC):
     :param number: the percent number to format
     :param format:
     :param locale: the `Locale` object or locale identifier
-    :return: the formatted percent number
-    :rtype: `unicode`
     """
     locale = Locale.parse(locale)
     if not format:
@@ -235,6 +221,7 @@ def format_percent(number, format=None, locale=LC_NUMERIC):
     pattern = parse_pattern(format)
     return pattern.apply(number, locale)
 
+
 def format_scientific(number, format=None, locale=LC_NUMERIC):
     """Return value formatted in scientific notation for a specific locale.
 
@@ -249,8 +236,6 @@ def format_scientific(number, format=None, locale=LC_NUMERIC):
     :param number: the number to format
     :param format:
     :param locale: the `Locale` object or locale identifier
-    :return: value formatted in scientific notation.
-    :rtype: `unicode`
     """
     locale = Locale.parse(locale)
     if not format:
@@ -288,6 +273,7 @@ def parse_number(string, locale=LC_NUMERIC):
     except ValueError:
         raise NumberFormatError('%r is not a valid number' % string)
 
+
 def parse_decimal(string, locale=LC_NUMERIC):
     """Parse localized decimal string into a decimal.
 
@@ -305,10 +291,8 @@ def parse_decimal(string, locale=LC_NUMERIC):
 
     :param string: the string to parse
     :param locale: the `Locale` object or locale identifier
-    :return: the parsed decimal number
-    :rtype: `Decimal`
-    :raise `NumberFormatError`: if the string can not be converted to a
-                                decimal number
+    :raise NumberFormatError: if the string can not be converted to a
+                              decimal number
     """
     locale = Locale.parse(locale)
     try:
@@ -375,6 +359,7 @@ def split_number(value):
         a, b = text, ''
     return a, b
 
+
 def bankersround(value, ndigits=0):
     """Round a number to a given precision.