mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-13 07:47:14 +03:00
Merge pull request #2255 from ElSaico/deprecation
Enabled DeprecationWarning by default and fixed references
This commit is contained in:
commit
55311725bc
@ -42,6 +42,7 @@ import logging.handlers
|
|||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import warnings
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
# So that any warning about accessing a protected member is only in one place.
|
# So that any warning about accessing a protected member is only in one place.
|
||||||
@ -99,6 +100,8 @@ logging.Logger.trace = lambda self, message, *args, **kwargs: self._log( # type
|
|||||||
# MAGIC-CONT: See MAGIC tagged comment in Logger.__init__()
|
# MAGIC-CONT: See MAGIC tagged comment in Logger.__init__()
|
||||||
logging.Formatter.converter = gmtime
|
logging.Formatter.converter = gmtime
|
||||||
|
|
||||||
|
warnings.simplefilter('default', DeprecationWarning)
|
||||||
|
|
||||||
|
|
||||||
def _trace_if(self: logging.Logger, condition: str, message: str, *args, **kwargs) -> None:
|
def _trace_if(self: logging.Logger, condition: str, message: str, *args, **kwargs) -> None:
|
||||||
if any(fnmatch(condition, p) for p in config_mod.trace_on):
|
if any(fnmatch(condition, p) for p in config_mod.trace_on):
|
||||||
|
@ -396,7 +396,7 @@ if TYPE_CHECKING:
|
|||||||
from logging import TRACE # type: ignore # noqa: F401 # Needed to update mypy
|
from logging import TRACE # type: ignore # noqa: F401 # Needed to update mypy
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
from infi.systray import SysTrayIcon
|
from simplesystray import SysTrayIcon
|
||||||
# isort: on
|
# isort: on
|
||||||
|
|
||||||
|
|
||||||
@ -452,7 +452,7 @@ class AppWindow:
|
|||||||
self.prefsdialog = None
|
self.prefsdialog = None
|
||||||
|
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
from infi.systray import SysTrayIcon
|
from simplesystray import SysTrayIcon
|
||||||
|
|
||||||
def open_window(systray: 'SysTrayIcon') -> None:
|
def open_window(systray: 'SysTrayIcon') -> None:
|
||||||
self.w.deiconify()
|
self.w.deiconify()
|
||||||
|
@ -41,7 +41,6 @@ import pathlib
|
|||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
|
||||||
import warnings
|
import warnings
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from typing import Any, Callable, Type, TypeVar
|
from typing import Any, Callable, Type, TypeVar
|
||||||
@ -329,8 +328,8 @@ class AbstractConfig(abc.ABC):
|
|||||||
:raises OSError: On Windows, if a Registry error occurs.
|
:raises OSError: On Windows, if a Registry error occurs.
|
||||||
:return: The data or the default.
|
:return: The data or the default.
|
||||||
"""
|
"""
|
||||||
warnings.warn(DeprecationWarning('get is Deprecated. use the specific getter for your type'))
|
# DEPRECATED: Migrate to specific type getters. Will remove in 6.0 or later.
|
||||||
logger.debug('Attempt to use Deprecated get() method\n' + ''.join(traceback.format_stack()))
|
warnings.warn('get is Deprecated. use the specific getter for your type', DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
if (a_list := self._suppress_call(self.get_list, ValueError, key, default=None)) is not None:
|
if (a_list := self._suppress_call(self.get_list, ValueError, key, default=None)) is not None:
|
||||||
return a_list
|
return a_list
|
||||||
@ -388,8 +387,8 @@ class AbstractConfig(abc.ABC):
|
|||||||
See get_int for its replacement.
|
See get_int for its replacement.
|
||||||
:raises OSError: On Windows, if a Registry error occurs.
|
:raises OSError: On Windows, if a Registry error occurs.
|
||||||
"""
|
"""
|
||||||
warnings.warn(DeprecationWarning('getint is Deprecated. Use get_int instead'))
|
# DEPRECATED: Migrate to get_int. Will remove in 6.0 or later.
|
||||||
logger.debug('Attempt to use Deprecated getint() method\n' + ''.join(traceback.format_stack()))
|
warnings.warn('getint is Deprecated. Use get_int instead', DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
return self.get_int(key, default=default)
|
return self.get_int(key, default=default)
|
||||||
|
|
||||||
@ -446,17 +445,19 @@ class AbstractConfig(abc.ABC):
|
|||||||
"""Close this config and release any associated resources."""
|
"""Close this config and release any associated resources."""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
# DEPRECATED: Password system doesn't do anything. Will remove in 6.0 or later.
|
||||||
def get_password(self, account: str) -> None:
|
def get_password(self, account: str) -> None:
|
||||||
"""Legacy password retrieval."""
|
"""Legacy password retrieval."""
|
||||||
warnings.warn("password subsystem is no longer supported", DeprecationWarning)
|
warnings.warn("password subsystem is no longer supported", DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
def set_password(self, account: str, password: str) -> None:
|
def set_password(self, account: str, password: str) -> None:
|
||||||
"""Legacy password setting."""
|
"""Legacy password setting."""
|
||||||
warnings.warn("password subsystem is no longer supported", DeprecationWarning)
|
warnings.warn("password subsystem is no longer supported", DeprecationWarning, stacklevel=2)
|
||||||
|
|
||||||
def delete_password(self, account: str) -> None:
|
def delete_password(self, account: str) -> None:
|
||||||
"""Legacy password deletion."""
|
"""Legacy password deletion."""
|
||||||
warnings.warn("password subsystem is no longer supported", DeprecationWarning)
|
warnings.warn("password subsystem is no longer supported", DeprecationWarning, stacklevel=2)
|
||||||
|
# End Dep Zone
|
||||||
|
|
||||||
|
|
||||||
def get_config(*args, **kwargs) -> AbstractConfig:
|
def get_config(*args, **kwargs) -> AbstractConfig:
|
||||||
@ -489,5 +490,10 @@ def get_update_feed() -> str:
|
|||||||
return 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml'
|
return 'https://raw.githubusercontent.com/EDCD/EDMarketConnector/releases/edmarketconnector.xml'
|
||||||
|
|
||||||
|
|
||||||
# WARNING: update_feed is deprecated, and will be removed in 6.0 or later. Please migrate to get_update_feed()
|
# DEPRECATED: Migrate to get_update_feed(). Will remove in 6.0 or later.
|
||||||
update_feed = get_update_feed()
|
def __getattr__(name: str):
|
||||||
|
if name == 'update_feed':
|
||||||
|
warnings.warn('update_feed is deprecated, and will be removed in 6.0 or later. '
|
||||||
|
'Please migrate to get_update_feed()', DeprecationWarning, stacklevel=2)
|
||||||
|
return get_update_feed()
|
||||||
|
raise AttributeError(name=name)
|
||||||
|
23
l10n.py
23
l10n.py
@ -86,8 +86,7 @@ class Translations:
|
|||||||
Use when translation is not desired or not available
|
Use when translation is not desired or not available
|
||||||
"""
|
"""
|
||||||
self.translations = {None: {}}
|
self.translations = {None: {}}
|
||||||
# WARNING: '_' is Deprecated. Will be removed in 6.0 or later.
|
# DEPRECATED: Migrate to translations.translate or tr.tl. Will remove in 6.0 or later.
|
||||||
# Migrate to calling translations.translate or tr.tl directly.
|
|
||||||
builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', '"').replace('{CR}', '\n')
|
builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', '"').replace('{CR}', '\n')
|
||||||
|
|
||||||
def install(self, lang: str | None = None) -> None: # noqa: CCR001
|
def install(self, lang: str | None = None) -> None: # noqa: CCR001
|
||||||
@ -131,8 +130,7 @@ class Translations:
|
|||||||
except Exception:
|
except Exception:
|
||||||
logger.exception(f'Exception occurred while parsing {lang}.strings in plugin {plugin}')
|
logger.exception(f'Exception occurred while parsing {lang}.strings in plugin {plugin}')
|
||||||
|
|
||||||
# WARNING: '_' is Deprecated. Will be removed in 6.0 or later.
|
# DEPRECATED: Migrate to translations.translate or tr.tl. Will remove in 6.0 or later.
|
||||||
# Migrate to calling translations.translate or tr.tl directly.
|
|
||||||
builtins.__dict__['_'] = self.translate
|
builtins.__dict__['_'] = self.translate
|
||||||
|
|
||||||
def contents(self, lang: str, plugin_path: str | None = None) -> dict[str, str]:
|
def contents(self, lang: str, plugin_path: str | None = None) -> dict[str, str]:
|
||||||
@ -262,16 +260,19 @@ class Translations:
|
|||||||
class _Locale:
|
class _Locale:
|
||||||
"""Locale holds a few utility methods to convert data to and from localized versions."""
|
"""Locale holds a few utility methods to convert data to and from localized versions."""
|
||||||
|
|
||||||
|
# DEPRECATED: Migrate to _Locale.string_from_number. Will remove in 6.0 or later.
|
||||||
def stringFromNumber(self, number: float | int, decimals: int | None = None) -> str: # noqa: N802
|
def stringFromNumber(self, number: float | int, decimals: int | None = None) -> str: # noqa: N802
|
||||||
warnings.warn(DeprecationWarning('use _Locale.string_from_number instead.'))
|
warnings.warn('use _Locale.string_from_number instead.', DeprecationWarning, stacklevel=2)
|
||||||
return self.string_from_number(number, decimals) # type: ignore
|
return self.string_from_number(number, decimals) # type: ignore
|
||||||
|
|
||||||
|
# DEPRECATED: Migrate to _Locale.number_from_string. Will remove in 6.0 or later.
|
||||||
def numberFromString(self, string: str) -> int | float | None: # noqa: N802
|
def numberFromString(self, string: str) -> int | float | None: # noqa: N802
|
||||||
warnings.warn(DeprecationWarning('use _Locale.number_from_string instead.'))
|
warnings.warn('use _Locale.number_from_string instead.', DeprecationWarning, stacklevel=2)
|
||||||
return self.number_from_string(string)
|
return self.number_from_string(string)
|
||||||
|
|
||||||
|
# DEPRECATED: Migrate to _Locale.preferred_languages. Will remove in 6.0 or later.
|
||||||
def preferredLanguages(self) -> Iterable[str]: # noqa: N802
|
def preferredLanguages(self) -> Iterable[str]: # noqa: N802
|
||||||
warnings.warn(DeprecationWarning('use _Locale.preferred_languages instead.'))
|
warnings.warn('use _Locale.preferred_languages instead.', DeprecationWarning, stacklevel=2)
|
||||||
return self.preferred_languages()
|
return self.preferred_languages()
|
||||||
|
|
||||||
def string_from_number(self, number: float | int, decimals: int = 5) -> str:
|
def string_from_number(self, number: float | int, decimals: int = 5) -> str:
|
||||||
@ -362,13 +363,13 @@ Locale = _Locale()
|
|||||||
translations = Translations()
|
translations = Translations()
|
||||||
|
|
||||||
|
|
||||||
# WARNING: 'Translations' singleton is deprecated. Will be removed in 6.0 or later.
|
# DEPRECATED: Migrate to `translations`. Will be removed in 6.0 or later.
|
||||||
# Migrate to importing 'translations'.
|
# 'Translations' singleton is deprecated.
|
||||||
# Begin Deprecation Zone
|
# Begin Deprecation Zone
|
||||||
class _Translations(Translations):
|
class _Translations(Translations):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
logger.warning(DeprecationWarning('Translations and _Translations() are deprecated. '
|
warnings.warn('Translations and _Translations() are deprecated. '
|
||||||
'Please use translations and Translations() instead.'))
|
'Please use translations and Translations() instead.', DeprecationWarning, stacklevel=2)
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
import warnings
|
||||||
from tkinter import ttk, messagebox
|
from tkinter import ttk, messagebox
|
||||||
from PIL import ImageGrab
|
from PIL import ImageGrab
|
||||||
from l10n import translations as tr
|
from l10n import translations as tr
|
||||||
@ -126,6 +127,7 @@ class Entry(EntryMenu):
|
|||||||
|
|
||||||
# DEPRECATED: Migrate to EntryMenu. Will remove in 6.0 or later.
|
# DEPRECATED: Migrate to EntryMenu. Will remove in 6.0 or later.
|
||||||
def __init__(self, master: ttk.Frame | None = None, **kw):
|
def __init__(self, master: ttk.Frame | None = None, **kw):
|
||||||
|
warnings.warn('Migrate to EntryMenu. Will remove in 6.0 or later.', DeprecationWarning, stacklevel=2)
|
||||||
EntryMenu.__init__(self, master, **kw)
|
EntryMenu.__init__(self, master, **kw)
|
||||||
|
|
||||||
|
|
||||||
@ -144,6 +146,7 @@ class ColoredButton(tk.Button):
|
|||||||
|
|
||||||
# DEPRECATED: Migrate to tk.Button. Will remove in 6.0 or later.
|
# DEPRECATED: Migrate to tk.Button. Will remove in 6.0 or later.
|
||||||
def __init__(self, master: ttk.Frame | None = None, **kw):
|
def __init__(self, master: ttk.Frame | None = None, **kw):
|
||||||
|
warnings.warn('Migrate to tk.Button. Will remove in 6.0 or later.', DeprecationWarning, stacklevel=2)
|
||||||
tk.Button.__init__(self, master, **kw)
|
tk.Button.__init__(self, master, **kw)
|
||||||
|
|
||||||
|
|
||||||
|
9
prefs.py
9
prefs.py
@ -9,6 +9,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
import warnings
|
||||||
from os import system
|
from os import system
|
||||||
from os.path import expanduser, expandvars, join, normpath
|
from os.path import expanduser, expandvars, join, normpath
|
||||||
from tkinter import colorchooser as tkColorChooser # type: ignore # noqa: N812
|
from tkinter import colorchooser as tkColorChooser # type: ignore # noqa: N812
|
||||||
@ -37,13 +38,11 @@ logger = get_main_logger()
|
|||||||
|
|
||||||
# May be imported by plugins
|
# May be imported by plugins
|
||||||
|
|
||||||
|
# DEPRECATED: Migrate to open_log_folder. Will remove in 6.0 or later.
|
||||||
def help_open_log_folder() -> None:
|
def help_open_log_folder() -> None:
|
||||||
"""Open the folder logs are stored in."""
|
"""Open the folder logs are stored in."""
|
||||||
logger.warning(
|
warnings.warn('prefs.help_open_log_folder is deprecated, use open_log_folder instead. '
|
||||||
DeprecationWarning("This function is deprecated, use open_log_folder instead. "
|
'This function will be removed in 6.0 or later', DeprecationWarning, stacklevel=2)
|
||||||
"This function will be removed in 6.0 or later")
|
|
||||||
)
|
|
||||||
open_folder(pathlib.Path(tempfile.gettempdir()) / appname)
|
open_folder(pathlib.Path(tempfile.gettempdir()) / appname)
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ wheel
|
|||||||
# We can't rely on just picking this up from either the base (not venv),
|
# We can't rely on just picking this up from either the base (not venv),
|
||||||
# or venv-init-time version. Specify here so that dependabot will prod us
|
# or venv-init-time version. Specify here so that dependabot will prod us
|
||||||
# about new versions.
|
# about new versions.
|
||||||
setuptools==69.2.0
|
setuptools==70.0.0
|
||||||
|
|
||||||
# Static analysis tools
|
# Static analysis tools
|
||||||
flake8==7.0.0
|
flake8==7.0.0
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
requests==2.32.3
|
requests==2.32.3
|
||||||
pillow==10.3.0
|
pillow==10.3.0
|
||||||
watchdog==4.0.0
|
watchdog==4.0.0
|
||||||
infi.systray==0.1.12; sys_platform == 'win32'
|
simplesystray==0.1.0; sys_platform == 'win32'
|
||||||
semantic-version==2.10.0
|
semantic-version==2.10.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user