]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Fixed issue #109: `ImportWarning` warned when `import babel` 177/head
authorPhilip_Tzou <philip.npc@gmail.com>
Sat, 1 Aug 2015 21:03:14 +0000 (14:03 -0700)
committerPhilip_Tzou <philip.npc@gmail.com>
Sat, 1 Aug 2015 21:18:12 +0000 (14:18 -0700)
`localedata.py` uses the same name with folder `localedata/`, which
Python will try to load `localdata/__init__.py` and warn `ImportWarning`
if the file not found.

If try to filter the `ImportWarning` as an error like this:

```python
import warnings
warnings.filterwarnings('error', category=ImportWarning)
import babel
```

An `ImportWarning` exception will be raised.

babel/localedata/.gitignore
babel/localedata/__init__.py [moved from babel/localedata.py with 94% similarity]

index 72e8ffc0db8aad71a934dd11e5968bd5109e54b4..2cbf0fc75d7a021120fd386648df8a42dfecf38e 100644 (file)
@@ -1 +1,2 @@
 *
+!__init__.py
similarity index 94%
rename from babel/localedata.py
rename to babel/localedata/__init__.py
index 88883ac80ef2ebf4313d86e71a7cde4b99a148e8..e6df0c4d134f0bfce15daed89b7ec1e6d988c3d2 100644 (file)
@@ -5,8 +5,8 @@
 
     Low-level locale data access.
 
-    :note: The `Locale` class, which uses this module under the hood, provides a
-           more convenient interface for accessing the locale data.
+    :note: The `Locale` class, which uses this module under the hood, provides
+           more convenient interface for accessing the locale data.
 
     :copyright: (c) 2013 by the Babel Team.
     :license: BSD, see LICENSE for more details.
@@ -21,7 +21,7 @@ from babel._compat import pickle
 
 _cache = {}
 _cache_lock = threading.RLock()
-_dirname = os.path.join(os.path.dirname(__file__), 'localedata')
+_dirname = os.path.dirname(__file__)
 
 
 def exists(name):
@@ -187,13 +187,13 @@ class LocaleDataDict(MutableMapping):
 
     def __getitem__(self, key):
         orig = val = self._data[key]
-        if isinstance(val, Alias): # resolve an alias
+        if isinstance(val, Alias):  # resolve an alias
             val = val.resolve(self.base)
-        if isinstance(val, tuple): # Merge a partial dict with an alias
+        if isinstance(val, tuple):  # Merge a partial dict with an alias
             alias, others = val
             val = alias.resolve(self.base).copy()
             merge(val, others)
-        if type(val) is dict: # Return a nested alias-resolving dict
+        if type(val) is dict:  # Return a nested alias-resolving dict
             val = LocaleDataDict(val, base=self.base)
         if val is not orig:
             self._data[key] = val