-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modified normalize_locale and exists to handle various unexpected input #523
Conversation
made normalize_locale and exists to handle various unexpected input such as list or None resolves: python-babel#521
babel/localedata.py
Outdated
name = name.strip().lower() | ||
for locale_id in chain.from_iterable([_cache, locale_identifiers()]): | ||
if name == locale_id.lower(): | ||
return locale_id | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
SpaceConsistencyBear, severity NORMAL, section default
.
The issue can be fixed by applying the following patch:
--- a/babel/localedata.py
+++ b/babel/localedata.py
@@ -47,7 +47,7 @@
for locale_id in chain.from_iterable([_cache, locale_identifiers()]):
if name == locale_id.lower():
return locale_id
-
+
def exists(name):
"""Check whether locale data is available for the given locale.
Codecov Report
@@ Coverage Diff @@
## master #523 +/- ##
==========================================
- Coverage 90.19% 88.84% -1.36%
==========================================
Files 24 24
Lines 4020 4024 +4
==========================================
- Hits 3626 3575 -51
- Misses 394 449 +55
Continue to review full report at Codecov.
|
babel/localedata.py
Outdated
name = name.strip().lower() | ||
for locale_id in chain.from_iterable([_cache, locale_identifiers()]): | ||
if name == locale_id.lower(): | ||
return locale_id | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
SpaceConsistencyBear, severity NORMAL, section default
.
The issue can be fixed by applying the following patch:
--- a/babel/localedata.py
+++ b/babel/localedata.py
@@ -47,7 +47,7 @@
for locale_id in chain.from_iterable([_cache, locale_identifiers()]):
if name == locale_id.lower():
return locale_id
-
+
def exists(name):
"""Check whether locale data is available for the given locale.
babel/localedata.py
Outdated
name = name.strip().lower() | ||
for locale_id in chain.from_iterable([_cache, locale_identifiers()]): | ||
if name == locale_id.lower(): | ||
return locale_id | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
SpaceConsistencyBear, severity NORMAL, section default
.
The issue can be fixed by applying the following patch:
--- a/babel/localedata.py
+++ b/babel/localedata.py
@@ -47,7 +47,7 @@
for locale_id in chain.from_iterable([_cache, locale_identifiers()]):
if name == locale_id.lower():
return locale_id
-
+
def exists(name):
"""Check whether locale data is available for the given locale.
babel/localedata.py
Outdated
name = name.strip().lower() | ||
for locale_id in chain.from_iterable([_cache, locale_identifiers()]): | ||
if name == locale_id.lower(): | ||
return locale_id | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
SpaceConsistencyBear, severity NORMAL, section default
.
The issue can be fixed by applying the following patch:
--- a/babel/localedata.py
+++ b/babel/localedata.py
@@ -47,7 +47,7 @@
for locale_id in chain.from_iterable([_cache, locale_identifiers()]):
if name == locale_id.lower():
return locale_id
-
+
def exists(name):
"""Check whether locale data is available for the given locale.
babel/localedata.py
Outdated
name = name.strip().lower() | ||
for locale_id in chain.from_iterable([_cache, locale_identifiers()]): | ||
if name == locale_id.lower(): | ||
return locale_id | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line contains following spacing inconsistencies:
- Trailing whitespaces.
SpaceConsistencyBear, severity NORMAL, section default
.
The issue can be fixed by applying the following patch:
--- a/babel/localedata.py
+++ b/babel/localedata.py
@@ -47,7 +47,7 @@
for locale_id in chain.from_iterable([_cache, locale_identifiers()]):
if name == locale_id.lower():
return locale_id
-
+
def exists(name):
"""Check whether locale data is available for the given locale.
@@ -41,6 +41,8 @@ def normalize_locale(name): | |||
Returns the normalized locale ID string or `None` if the ID is not | |||
recognized. | |||
""" | |||
if not name or not isinstance(name, string_types): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably be better and/or more Pythonic to just cast to the text type here, instead of strictly requiring a string type.
@@ -54,6 +56,8 @@ def exists(name): | |||
|
|||
:param name: the locale identifier string | |||
""" | |||
if not name or not isinstance(name, string_types): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: It would probably be better and/or more Pythonic to just cast to the text type here, instead of strictly requiring a string type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps that's functionality that could be implemented at a later date?
Using isinstance()
would make it match the currency functions, e.g., https://github.com/python-babel/babel/blob/master/babel/numbers.py#L82.
I'm also not sure whether accepting an object for which str(obj)
returns a locale should be supported long-term?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose you're correct. Didn't remember the currency functions already acted like this anyway.
made normalize_locale and exists to handle various unexpected input such as list or None just like currency, and added test cases in test_localedata.py
resolves: #521