1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 07:47:14 +03:00

Enabled DeprecationWarning by default and fixed references

This commit is contained in:
Bruno Marques 2024-06-09 18:40:03 +01:00
parent 2c60499451
commit b0e682f66c
5 changed files with 25 additions and 21 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

@ -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,7 @@ 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()))
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 +386,7 @@ 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()))
warnings.warn('getint is Deprecated. Use get_int instead', DeprecationWarning, stacklevel=2)
return self.get_int(key, default=default)
@ -448,15 +445,15 @@ class AbstractConfig(abc.ABC):
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)
def get_config(*args, **kwargs) -> AbstractConfig:
@ -489,5 +486,9 @@ 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()
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)

10
l10n.py
View File

@ -263,15 +263,15 @@ class _Locale:
"""Locale holds a few utility methods to convert data to and from localized versions."""
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
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)
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:
@ -367,8 +367,8 @@ translations = Translations()
# 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
@ -124,8 +125,8 @@ class EntryMenu(ttk.Entry):
class Entry(EntryMenu):
"""Custom ttk.Entry class to fix some display issues."""
# 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)
@ -142,8 +143,8 @@ class Button(ttk.Button):
class ColoredButton(tk.Button):
"""Custom tk.Button class to fix some display issues."""
# 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
@ -40,10 +41,8 @@ logger = get_main_logger()
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)