1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-12 15:27:14 +03:00

Merge pull request #2255 from ElSaico/deprecation

Enabled DeprecationWarning by default and fixed references
This commit is contained in:
David Sangrey 2024-06-09 16:02:25 -04:00 committed by GitHub
commit 55311725bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 42 additions and 30 deletions

View File

@ -42,6 +42,7 @@ import logging.handlers
import os
import pathlib
import tempfile
import warnings
from contextlib import suppress
from fnmatch import fnmatch
# 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__()
logging.Formatter.converter = gmtime
warnings.simplefilter('default', DeprecationWarning)
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):

View File

@ -396,7 +396,7 @@ if TYPE_CHECKING:
from logging import TRACE # type: ignore # noqa: F401 # Needed to update mypy
if sys.platform == 'win32':
from infi.systray import SysTrayIcon
from simplesystray import SysTrayIcon
# isort: on
@ -452,7 +452,7 @@ class AppWindow:
self.prefsdialog = None
if sys.platform == 'win32':
from infi.systray import SysTrayIcon
from simplesystray import SysTrayIcon
def open_window(systray: 'SysTrayIcon') -> None:
self.w.deiconify()

View File

@ -41,7 +41,6 @@ import pathlib
import re
import subprocess
import sys
import traceback
import warnings
from abc import abstractmethod
from typing import Any, Callable, Type, TypeVar
@ -329,8 +328,8 @@ class AbstractConfig(abc.ABC):
:raises OSError: On Windows, if a Registry error occurs.
:return: The data or the default.
"""
warnings.warn(DeprecationWarning('get is Deprecated. use the specific getter for your type'))
logger.debug('Attempt to use Deprecated get() method\n' + ''.join(traceback.format_stack()))
# DEPRECATED: Migrate to specific type getters. Will remove in 6.0 or later.
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:
return a_list
@ -388,8 +387,8 @@ class AbstractConfig(abc.ABC):
See get_int for its replacement.
:raises OSError: On Windows, if a Registry error occurs.
"""
warnings.warn(DeprecationWarning('getint is Deprecated. Use get_int instead'))
logger.debug('Attempt to use Deprecated getint() method\n' + ''.join(traceback.format_stack()))
# DEPRECATED: Migrate to get_int. Will remove in 6.0 or later.
warnings.warn('getint is Deprecated. Use get_int instead', DeprecationWarning, stacklevel=2)
return self.get_int(key, default=default)
@ -446,17 +445,19 @@ class AbstractConfig(abc.ABC):
"""Close this config and release any associated resources."""
raise NotImplementedError
# DEPRECATED: Password system doesn't do anything. Will remove in 6.0 or later.
def get_password(self, account: str) -> None:
"""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:
"""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:
"""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:
@ -489,5 +490,10 @@ def get_update_feed() -> str:
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()
update_feed = get_update_feed()
# DEPRECATED: Migrate to get_update_feed(). Will remove in 6.0 or later.
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
View File

@ -86,8 +86,7 @@ class Translations:
Use when translation is not desired or not available
"""
self.translations = {None: {}}
# WARNING: '_' is Deprecated. Will be removed in 6.0 or later.
# Migrate to calling translations.translate or tr.tl directly.
# DEPRECATED: Migrate to translations.translate or tr.tl. Will remove in 6.0 or later.
builtins.__dict__['_'] = lambda x: str(x).replace(r'\"', '"').replace('{CR}', '\n')
def install(self, lang: str | None = None) -> None: # noqa: CCR001
@ -131,8 +130,7 @@ class Translations:
except Exception:
logger.exception(f'Exception occurred while parsing {lang}.strings in plugin {plugin}')
# WARNING: '_' is Deprecated. Will be removed in 6.0 or later.
# Migrate to calling translations.translate or tr.tl directly.
# DEPRECATED: Migrate to translations.translate or tr.tl. Will remove in 6.0 or later.
builtins.__dict__['_'] = self.translate
def contents(self, lang: str, plugin_path: str | None = None) -> dict[str, str]:
@ -262,16 +260,19 @@ class Translations:
class _Locale:
"""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
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
# DEPRECATED: Migrate to _Locale.number_from_string. Will remove in 6.0 or later.
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)
# DEPRECATED: Migrate to _Locale.preferred_languages. Will remove in 6.0 or later.
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()
def string_from_number(self, number: float | int, decimals: int = 5) -> str:
@ -362,13 +363,13 @@ Locale = _Locale()
translations = Translations()
# WARNING: 'Translations' singleton is deprecated. Will be removed in 6.0 or later.
# Migrate to importing 'translations'.
# DEPRECATED: Migrate to `translations`. Will be removed in 6.0 or later.
# 'Translations' singleton is deprecated.
# Begin Deprecation Zone
class _Translations(Translations):
def __init__(self):
logger.warning(DeprecationWarning('Translations and _Translations() are deprecated. '
'Please use translations and Translations() instead.'))
warnings.warn('Translations and _Translations() are deprecated. '
'Please use translations and Translations() instead.', DeprecationWarning, stacklevel=2)
super().__init__()

View File

@ -11,6 +11,7 @@ from __future__ import annotations
import sys
import tkinter as tk
import warnings
from tkinter import ttk, messagebox
from PIL import ImageGrab
from l10n import translations as tr
@ -126,6 +127,7 @@ class Entry(EntryMenu):
# DEPRECATED: Migrate to EntryMenu. Will remove in 6.0 or later.
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)
@ -144,6 +146,7 @@ class ColoredButton(tk.Button):
# DEPRECATED: Migrate to tk.Button. Will remove in 6.0 or later.
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)

View File

@ -9,6 +9,7 @@ import subprocess
import sys
import tempfile
import tkinter as tk
import warnings
from os import system
from os.path import expanduser, expandvars, join, normpath
from tkinter import colorchooser as tkColorChooser # type: ignore # noqa: N812
@ -37,13 +38,11 @@ logger = get_main_logger()
# May be imported by plugins
# DEPRECATED: Migrate to open_log_folder. Will remove in 6.0 or later.
def help_open_log_folder() -> None:
"""Open the folder logs are stored in."""
logger.warning(
DeprecationWarning("This function is deprecated, use open_log_folder instead. "
"This function will be removed in 6.0 or later")
)
warnings.warn('prefs.help_open_log_folder is deprecated, use open_log_folder instead. '
'This function will be removed in 6.0 or later', DeprecationWarning, stacklevel=2)
open_folder(pathlib.Path(tempfile.gettempdir()) / appname)

View File

@ -5,7 +5,7 @@ wheel
# 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
# about new versions.
setuptools==69.2.0
setuptools==70.0.0
# Static analysis tools
flake8==7.0.0

View File

@ -1,5 +1,5 @@
requests==2.32.3
pillow==10.3.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