diff --git a/source/appModuleHandler.py b/source/appModuleHandler.py index 565354a51d0..fad70637ea6 100644 --- a/source/appModuleHandler.py +++ b/source/appModuleHandler.py @@ -89,7 +89,7 @@ def __getattr__(attrName: str) -> Any: since add-ons are initialized before `appModuleHandler` and when `appModuleHandler` was not yet initialized the variable was set to `None`. """ - if attrName == "NVDAProcessID": + if attrName == "NVDAProcessID" and globalVars._useDeprecatedAPI: log.warning("appModuleHandler.NVDAProcessID is deprecated, use globalVars.appPid instead.") if initialize._alreadyInitialized: return globalVars.appPid @@ -112,12 +112,14 @@ def _warnDeprecatedAliasAppModule() -> None: except KeyError: raise RuntimeError("This function can be executed only inside an alias App Module.") from None else: - log.warning( - ( - f"Importing from appModules.{currModName} is deprecated," - f" you should import from appModules.{replacementModName}." - ) + importFailMsg = ( + f"Importing appModules.{currModName} is deprecated," + f" instead import appModules.{replacementModName}." ) + if globalVars._useDeprecatedAPI: + log.warning(importFailMsg) + else: + raise ModuleNotFoundError(importFailMsg) def registerExecutableWithAppModule(executableName: str, appModName: str) -> None: diff --git a/source/config/__init__.py b/source/config/__init__.py index 220e06a4060..09c757c7a46 100644 --- a/source/config/__init__.py +++ b/source/config/__init__.py @@ -10,8 +10,6 @@ For the latter two actions, one can perform actions prior to and/or after they take place. """ - -from buildVersion import version_year from enum import Enum import globalVars import winreg @@ -88,17 +86,15 @@ class RegistryKey(str, Enum): """ -if version_year < 2023: +if globalVars._useDeprecatedAPI: RUN_REGKEY = RegistryKey.RUN.value """ - Deprecated, for removal in 2023. - Use L{RegistryKey.RUN} instead. + Deprecated, use L{RegistryKey.RUN} instead. """ NVDA_REGKEY = RegistryKey.NVDA.value """ - Deprecated, for removal in 2023. - Use L{RegistryKey.NVDA} instead. + Deprecated, use L{RegistryKey.NVDA} instead. """ diff --git a/source/easeOfAccess.py b/source/easeOfAccess.py index 9550134b720..ebe100aef1d 100644 --- a/source/easeOfAccess.py +++ b/source/easeOfAccess.py @@ -6,9 +6,10 @@ """Utilities for working with the Windows Ease of Access Center. """ -from buildVersion import version_year from enum import Enum, IntEnum from typing import List + +import globalVars from logHandler import log import winreg import winUser @@ -32,20 +33,18 @@ class AutoStartContext(IntEnum): AFTER_LOGON = winreg.HKEY_CURRENT_USER -if version_year < 2023: +if globalVars._useDeprecatedAPI: ROOT_KEY = RegistryKey.ROOT.value """ - Deprecated, for removal in 2023. - Use L{RegistryKey.ROOT} instead. + Deprecated, use L{RegistryKey.ROOT} instead. """ APP_KEY_NAME = _APP_KEY_NAME - """Deprecated, for removal in 2023""" + """Deprecated for removal""" APP_KEY_PATH = RegistryKey.APP.value """ - Deprecated, for removal in 2023. - Use L{RegistryKey.APP} instead. + Deprecated, use L{RegistryKey.APP} instead. """ diff --git a/source/globalVars.py b/source/globalVars.py index c806efd461b..6501fcfd091 100644 --- a/source/globalVars.py +++ b/source/globalVars.py @@ -69,3 +69,15 @@ class DefaultAppArgs(argparse.Namespace): appPid: int = 0 """The process ID of NVDA itself. """ + +_useDeprecatedAPI: bool = True +""" +Used for marking code as deprecated. +This should never be False in released code. + +Making this False may be useful for testing if code +is compliant without using deprecated APIs. +Note that deprecated code may be imported at runtime, +and as such, this value cannot be changed at runtime +to test compliance. +""" diff --git a/source/gui/__init__.py b/source/gui/__init__.py index 0950ae37b46..2ec9e3b9595 100644 --- a/source/gui/__init__.py +++ b/source/gui/__init__.py @@ -46,14 +46,12 @@ import speechViewer import winUser import api -from buildVersion import version_year -if version_year < 2023: +if globalVars._useDeprecatedAPI: def quit(): """ - Deprecated, for removal in 2023.1. - Use `wx.CallAfter(mainFrame.onExitCommand, None)` directly instead. + Deprecated, use `wx.CallAfter(mainFrame.onExitCommand, None)` directly instead. """ log.debugWarning("Deprecated function called: gui.quit", stack_info=True) wx.CallAfter(mainFrame.onExitCommand, None) diff --git a/user_docs/en/changes.t2t b/user_docs/en/changes.t2t index 9f960c6e553..fdb4132ee58 100644 --- a/user_docs/en/changes.t2t +++ b/user_docs/en/changes.t2t @@ -85,12 +85,11 @@ Please test the new API and provide feedback. For add-on authors, please open a GitHub issue if these changes stop the API from meeting your needs. -- ``appModuleHandler.NVDAProcessID`` is deprecated - use ``globalVars.appPid`` instead. (#13646) -- ``gui.quit`` has been deprecated for removal in 2023.1. (#13498) - - Use ``wx.CallAfter(mainFrame.onExitCommand, None)`` directly instead. +- ``appModuleHandler.NVDAProcessID`` is deprecated, use ``globalVars.appPid`` instead. (#13646) +- ``gui.quit`` is deprecated, use ``wx.CallAfter(mainFrame.onExitCommand, None)`` instead. (#13498) - % Insert new list items here as the alias appModule table should be kept at the bottom of this list -- Some alias appModules are marked as deprecated and will be removed in 2023.1. +- Some alias appModules are marked as deprecated. Code which imports from one of them, should instead import from the replacement module. (#13366) -