Skip to content

Commit 9230fb0

Browse files
authored
Merge da27960 into 01f3e1e
2 parents 01f3e1e + da27960 commit 9230fb0

File tree

16 files changed

+23
-181
lines changed

16 files changed

+23
-181
lines changed

source/_addonStore/dataManager.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

6-
# Needed for type hinting CaseInsensitiveDict
7-
# Can be removed in a future version of python (3.8+)
8-
from __future__ import annotations
9-
106
from copy import deepcopy
117
import json
128
import os

source/_addonStore/install.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

6-
# Needed for type hinting CaseInsensitiveDict
7-
# Can be removed in a future version of python (3.8+)
8-
from __future__ import annotations
9-
106
from os import (
117
PathLike,
128
)

source/_addonStore/models/addon.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

6-
# Needed for type hinting CaseInsensitiveDict
7-
# Can be removed in a future version of python (3.8+)
8-
from __future__ import annotations
9-
106
import dataclasses
117
import json
128
import os

source/_addonStore/network.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

6-
# Needed for type hinting Future
7-
# Can be removed in a future version of python (3.8+)
8-
from __future__ import annotations
9-
106
from concurrent.futures import (
117
Future,
128
ThreadPoolExecutor,

source/addonHandler/__init__.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
# This file is covered by the GNU General Public License.
55
# See the file COPYING for more details.
66

7-
# Needed for type hinting CaseInsensitiveDict, UserDict
8-
# Can be removed in a future version of python (3.8+)
9-
from __future__ import annotations
10-
117
from abc import abstractmethod, ABC
128
import sys
139
import os.path
@@ -79,24 +75,25 @@
7975
isCLIParamKnown = extensionPoints.AccumulatingDecider(defaultDecision=False)
8076

8177

82-
class AddonsState(collections.UserDict):
78+
AddonStateDictT = Dict[AddonStateCategory, CaseInsensitiveSet[str]]
79+
80+
81+
class AddonsState(collections.UserDict[AddonStateCategory, CaseInsensitiveSet[str]]):
8382
"""
8483
Subclasses `collections.UserDict` to preserve backwards compatibility.
85-
In future versions of python (3.8+) UserDict[AddonStateCategory, CaseInsensitiveSet[str]]
86-
can have type information added.
8784
AddonStateCategory string enums mapped to a set of the add-on "name/id" currently in that state.
8885
Add-ons that have the same ID except differ in casing cause a path collision,
8986
as add-on IDs are installed to a case insensitive path.
9087
Therefore add-on IDs should be treated as case insensitive.
9188
"""
9289

9390
@staticmethod
94-
def _generateDefaultStateContent() -> Dict[AddonStateCategory, CaseInsensitiveSet[str]]:
91+
def _generateDefaultStateContent() -> AddonStateDictT:
9592
return {
9693
category: CaseInsensitiveSet() for category in AddonStateCategory
9794
}
9895

99-
data: Dict[AddonStateCategory, CaseInsensitiveSet[str]]
96+
data: AddonStateDictT
10097
manualOverridesAPIVersion: MajorMinorPatch
10198

10299
@property
@@ -224,7 +221,7 @@ def _cleanupCompatibleAddonsFromDowngrade(self) -> None:
224221
self[AddonStateCategory.OVERRIDE_COMPATIBILITY].discard(blockedAddon)
225222

226223

227-
state: AddonsState[AddonStateCategory, CaseInsensitiveSet[str]] = AddonsState()
224+
state = AddonsState()
228225

229226

230227
def getRunningAddons() -> "AddonHandlerModelGeneratorT":
@@ -762,8 +759,9 @@ def initTranslation():
762759
try:
763760
callerFrame = inspect.currentframe().f_back
764761
callerFrame.f_globals['_'] = translations.gettext
765-
# Install our pgettext function.
766-
callerFrame.f_globals['pgettext'] = languageHandler.makePgettext(translations)
762+
# Install pgettext and npgettext function.
763+
callerFrame.f_globals['pgettext'] = translations.pgettext
764+
callerFrame.f_globals['npgettext'] = translations.npgettext
767765
finally:
768766
del callerFrame # Avoid reference problems with frames (per python docs)
769767

source/gui/_addonStoreGui/viewModels/addonList.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

6-
# Needed for type hinting CaseInsensitiveDict
7-
# Can be removed in a future version of python (3.8+)
8-
from __future__ import annotations
96
from dataclasses import dataclass
107
from enum import Enum
118

source/gui/_addonStoreGui/viewModels/store.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

6-
# Needed for type hinting CaseInsensitiveDict
7-
# Can be removed in a future version of python (3.8+)
8-
from __future__ import annotations
9-
106
from os import (
117
PathLike,
128
startfile,

source/languageHandler.py

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
such as converting Windows locale ID's to friendly names and presenting available languages.
99
"""
1010

11-
import builtins
1211
import os
1312
import sys
1413
import ctypes
@@ -27,7 +26,6 @@
2726
Optional,
2827
Tuple,
2928
Union,
30-
Callable,
3129
)
3230

3331
#a few Windows locale constants
@@ -290,52 +288,6 @@ def getAvailableLanguages(presentational: bool = False) -> List[Tuple[str, str]]
290288
return langs
291289

292290

293-
def makePgettext(translations):
294-
"""Obtain a pgettext function for use with a gettext translations instance.
295-
pgettext is used to support message contexts,
296-
but Python 3.7's gettext module doesn't support this,
297-
so NVDA must provide its own implementation.
298-
"""
299-
if isinstance(translations, gettext.GNUTranslations):
300-
def pgettext(context, message):
301-
try:
302-
# Look up the message with its context.
303-
return translations._catalog[u"%s\x04%s" % (context, message)]
304-
except KeyError:
305-
return message
306-
elif isinstance(translations, gettext.NullTranslations):
307-
# A language without a translation catalog, such as English.
308-
def pgettext(context, message):
309-
return message
310-
else:
311-
raise ValueError("%s is Not a GNUTranslations or NullTranslations object" % translations)
312-
return pgettext
313-
314-
315-
def makeNpgettext(
316-
translations: Union[None, gettext.GNUTranslations, gettext.NullTranslations],
317-
) -> Callable[[str, str, str, Union[int, float]], str]:
318-
"""Obtain a npgettext function for use with a gettext translations instance.
319-
npgettext is used to support message contexts with respect to ngettext,
320-
but Python 3.7's gettext module doesn't support this,
321-
so NVDA must provide its own implementation.
322-
"""
323-
if isinstance(translations, gettext.GNUTranslations):
324-
def npgettext(context: str, msgSingular: str, msgPlural: str, n: Union[int, float]) -> str:
325-
try:
326-
# Look up the message with its context.
327-
return translations._catalog[(f"{context}\x04{msgSingular}", translations.plural(n))]
328-
except KeyError:
329-
return msgSingular if n == 1 else msgPlural
330-
elif isinstance(translations, gettext.NullTranslations):
331-
# A language without a translation catalog, such as English.
332-
def npgettext(context: str, msgSingular: str, msgPlural: str, n: Union[int, float]) -> str:
333-
return msgSingular if n == 1 else msgPlural
334-
else:
335-
raise ValueError("%s is Not a GNUTranslations or NullTranslations object" % translations)
336-
return npgettext
337-
338-
339291
def getLanguageCliArgs() -> Tuple[str, ...]:
340292
"""Returns all command line arguments which were used to set current NVDA language
341293
or an empty tuple if language has not been specified from the CLI."""
@@ -408,11 +360,8 @@ def setLanguage(lang: str) -> None:
408360
if trans is None:
409361
trans = _createGettextTranslation("en")
410362

411-
trans.install(names=['ngettext'])
363+
trans.install(names=["pgettext", "npgettext", "ngettext"])
412364
setLocale(getLanguage())
413-
# Install our pgettext and npgettext functions.
414-
builtins.pgettext = makePgettext(trans)
415-
builtins.npgettext = makeNpgettext(trans)
416365

417366
global installedTranslation
418367
installedTranslation = weakref.ref(trans)

source/monkeyPatches/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,3 @@ def applyMonkeyPatches():
1313
# Apply several monkey patches to comtypes
1414
from . import comtypesMonkeyPatches
1515
comtypesMonkeyPatches.applyMonkeyPatches()
16-
17-
# Apply patches to Enum, prevent cyclic references on ValueError during construction
18-
from . import enumPatches
19-
enumPatches.replace__new__()

source/monkeyPatches/enumPatches.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)