From: Philip_Tzou Date: Sat, 1 Aug 2015 21:03:14 +0000 (-0700) Subject: Fixed issue #109: `ImportWarning` warned when `import babel` X-Git-Tag: dev-2a51c9b95d06~39^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d387f95f4f41ed646bcb2b4fa39dae4a601b6ce;p=thirdparty%2Fbabel.git Fixed issue #109: `ImportWarning` warned when `import babel` `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. --- diff --git a/babel/localedata/.gitignore b/babel/localedata/.gitignore index 72e8ffc0..2cbf0fc7 100644 --- a/babel/localedata/.gitignore +++ b/babel/localedata/.gitignore @@ -1 +1,2 @@ * +!__init__.py diff --git a/babel/localedata.py b/babel/localedata/__init__.py similarity index 94% rename from babel/localedata.py rename to babel/localedata/__init__.py index 88883ac8..e6df0c4d 100644 --- a/babel/localedata.py +++ b/babel/localedata/__init__.py @@ -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 + a 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