mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-13 15:57:14 +03:00
Deprecated camelCase methods
Python prefers snake_case methods and camelCase classes. This replaces some camelCase methods with snake_case variants, and has the original names raise a DeprecationWarning before calling the snake_case versions
This commit is contained in:
parent
ac7a1fa63e
commit
b5282fc8ea
@ -227,7 +227,7 @@ a single set and two get methods, the new methods provide better type safety.
|
||||
**Be sure to use a unique prefix for any settings you save so as not to clash
|
||||
with core EDMC or other plugins.**
|
||||
|
||||
Use `numberFromString()` from EDMC's `l10n.Locale` object to parse input
|
||||
Use `number_from_string()` from EDMC's `l10n.Locale` object to parse input
|
||||
numbers in a locale-independent way.
|
||||
|
||||
Note that in the following example the function signature defines that it
|
||||
@ -288,7 +288,7 @@ For a more complicated item create a tk.Frame widget and populate it with other
|
||||
ttk widgets. Return `None` if you just want to use this as a callback after the
|
||||
main window and all other plugins are initialised.
|
||||
|
||||
You can use `stringFromNumber()` from EDMC's `l10n.Locale` object to format
|
||||
You can use `string_from_number()` from EDMC's `l10n.Locale` object to format
|
||||
numbers in your widgets in a locale-independent way.
|
||||
|
||||
```python
|
||||
|
21
l10n.py
21
l10n.py
@ -13,6 +13,7 @@ from contextlib import suppress
|
||||
from os.path import basename, dirname, exists, isdir, isfile, join
|
||||
from sys import platform
|
||||
from typing import TYPE_CHECKING, Dict, Iterable, Optional, Set, TextIO, Union, cast
|
||||
import warnings
|
||||
|
||||
if TYPE_CHECKING:
|
||||
def _(x: str) -> str: ...
|
||||
@ -93,7 +94,7 @@ class _Translations:
|
||||
available.add(_Translations.FALLBACK)
|
||||
if not lang:
|
||||
# Choose the default language
|
||||
for preferred in Locale.preferredLanguages():
|
||||
for preferred in Locale.preferred_languages():
|
||||
components = preferred.split('-')
|
||||
if preferred in available:
|
||||
lang = preferred
|
||||
@ -246,7 +247,19 @@ class _Locale:
|
||||
self.float_formatter.setMinimumFractionDigits_(5)
|
||||
self.float_formatter.setMaximumFractionDigits_(5)
|
||||
|
||||
def stringFromNumber(self, number: Union[float, int], decimals: int = None) -> str:
|
||||
def stringFromNumber(self, number: Union[float, int], decimals: int = None) -> str: # noqa: N802
|
||||
warnings.warn(DeprecationWarning('use _Locale.string_from_number instead.'))
|
||||
return self.stringFromNumber(number, decimals)
|
||||
|
||||
def numberFromString(self, string: str) -> Union[int, float, None]: # noqa: N802
|
||||
warnings.warn(DeprecationWarning('use _Locale.number_from_string instead.'))
|
||||
return self.numberFromString(string)
|
||||
|
||||
def preferredLanguages(self) -> Iterable[str]: # noqa: N802
|
||||
warnings.warn(DeprecationWarning('use _Locale.preferred_languages instead.'))
|
||||
return self.preferred_languages()
|
||||
|
||||
def string_from_number(self, number: Union[float, int], decimals: int = None) -> str:
|
||||
"""
|
||||
Convert a number to a string.
|
||||
|
||||
@ -275,7 +288,7 @@ class _Locale:
|
||||
else:
|
||||
return locale.format('%.*f', (decimals, number), True) # type: ignore # It ends up working out
|
||||
|
||||
def numberFromString(self, string: str) -> Union[int, float, None]:
|
||||
def number_from_string(self, string: str) -> Union[int, float, None]:
|
||||
"""
|
||||
Convert a string to a number using the system locale.
|
||||
|
||||
@ -294,7 +307,7 @@ class _Locale:
|
||||
|
||||
return None
|
||||
|
||||
def preferredLanguages(self) -> Iterable[str]:
|
||||
def preferred_languages(self) -> Iterable[str]:
|
||||
"""
|
||||
Return a list of preferred language codes.
|
||||
|
||||
|
2
stats.py
2
stats.py
@ -448,4 +448,4 @@ class StatsResults(tk.Toplevel):
|
||||
def credits(self, value: int) -> str:
|
||||
"""Localised string of given int, including a trailing ` Cr`."""
|
||||
# TODO: Locale is a class, this calls an instance method on it with an int as its `self`
|
||||
return Locale.stringFromNumber(value, 0) + ' Cr' # type: ignore
|
||||
return Locale.string_from_number(value, 0) + ' Cr' # type: ignore
|
||||
|
Loading…
x
Reference in New Issue
Block a user