Skip to content

Commit

Permalink
#3930 replace DummyContextManager with nullcontext
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jul 28, 2023
1 parent 12cc759 commit ae90878
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 23 deletions.
4 changes: 2 additions & 2 deletions tests/unittests/unit/client/mixins/mmap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import unittest

from xpra.os_util import DummyContextManager
from contextlib import nullcontext
from xpra.util import AdHocStruct
from xpra.client.mixins import mmap

Expand All @@ -24,7 +24,7 @@ def close(self):
import tempfile
tmp_dir = tempfile.gettempdir()
for mmap_option, ctx in {
"off" : DummyContextManager(),
"off" : nullcontext(),
"on" : silence_info(mmap),
tmp_dir+"/xpra-mmap-test-file-%i" % os.getpid() : silence_info(mmap),
tmp_dir+"/xpra-fail-mmap-test-file-%i" % os.getpid() : silence_error(mmap),
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/unit/codecs/video_colorspace_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import unittest
import binascii
from contextlib import nullcontext

from xpra.util import typedict
from xpra.os_util import hexstr
Expand Down Expand Up @@ -116,8 +117,7 @@ def test_all(self):
decodings = vh.get_decodings()
common = [x for x in encodings if x in decodings]
options = {"max-delayed" : 0}
from xpra.os_util import DummyContextManager
ctx = DummyContextManager()
ctx = nullcontext()
try:
from xpra.codecs.nvidia.cuda_context import get_default_device_context
ctx = get_default_device_context()
Expand Down
5 changes: 3 additions & 2 deletions tests/unittests/unit/server/mixins/child_command_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import os
import time
import unittest
from contextlib import nullcontext

from xpra.os_util import POSIX, DummyContextManager
from xpra.os_util import POSIX
from xpra.util import AdHocStruct
from unit.test_util import silence_info
from unit.server.mixins.servermixintest_util import ServerMixinTest
Expand All @@ -21,7 +22,7 @@ def test_command_server(self):
from xpra.platform.posix.xdg_helper import log
c = silence_info(log)
except ImportError:
c = DummyContextManager()
c = nullcontext()
with c:
self.do_test_command_server()

Expand Down
5 changes: 2 additions & 3 deletions xpra/client/gl/gl_window_backing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import time
from time import monotonic
from typing import Any, Callable, Iterable
from contextlib import AbstractContextManager
from contextlib import AbstractContextManager, nullcontext
from gi.repository import GLib # @UnresolvedImport

from OpenGL import version as OpenGL_version
Expand Down Expand Up @@ -59,7 +59,6 @@
from xpra.os_util import (
strtobytes, bytestostr, hexstr,
POSIX, OSX,
DummyContextManager,
)
from xpra.util import envint, envbool, repr_ellipsized, first_time, roundup
from xpra.common import noop
Expand Down Expand Up @@ -228,7 +227,7 @@ def py_gl_debug_callback(source, error_type, error_id, severity, length, message
else:
zerocopy_upload = OpenGL_version.__version__==OpenGL_accelerate.__version__

paint_context_manager: AbstractContextManager = DummyContextManager()
paint_context_manager: AbstractContextManager = nullcontext()
if POSIX and not OSX:
# pylint: disable=ungrouped-imports
from xpra.gtk_common.error import xsync
Expand Down
10 changes: 0 additions & 10 deletions xpra/os_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,16 +739,6 @@ def __repr__(self):
return "OSEnvContext"


class DummyContextManager:
__slots__ = ()
def __enter__(self):
""" do nothing """
def __exit__(self, *_args):
""" do nothing """
def __repr__(self):
return "DummyContextManager"


#workaround incompatibility between paramiko and gssapi:
class nomodule_context:
__slots__ = ("module_name", "saved_module")
Expand Down
5 changes: 3 additions & 2 deletions xpra/platform/posix/menu_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import sys
import glob
from time import monotonic
from contextlib import nullcontext
from typing import Any, Generator as generator #@UnresolvedImport, @UnusedImport

from xpra.util import envbool, first_time
from xpra.os_util import DummyContextManager, OSEnvContext, get_saved_env
from xpra.os_util import OSEnvContext, get_saved_env
from xpra.codecs import icon_util
from xpra.platform.paths import get_icon_filename
from xpra.log import Logger
Expand Down Expand Up @@ -75,7 +76,7 @@ def export(entry, properties : tuple[str, ...]) -> dict[str,Any]:
IconTheme : type | None = None
Config : type | None = None
themes : dict[str,Any] = {}
IconLoadingContext : type = DummyContextManager
IconLoadingContext : type = nullcontext
if LOAD_FROM_THEME:
try:
import xdg
Expand Down
5 changes: 3 additions & 2 deletions xpra/server/window/window_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
from math import sqrt, ceil
from collections import deque
from time import monotonic
from contextlib import nullcontext
from typing import Callable, Iterable, ContextManager, Any

from xpra.os_util import bytestostr, POSIX, OSX, DummyContextManager
from xpra.os_util import bytestostr, POSIX, OSX
from xpra.util import envint, envbool, csv, typedict, first_time, decode_str, repr_ellipsized
from xpra.common import MAX_WINDOW_SIZE, WINDOW_DECODE_SKIPPED, WINDOW_DECODE_ERROR, WINDOW_NOT_FOUND
from xpra.server.window.windowicon_source import WindowIconSource
Expand Down Expand Up @@ -114,7 +115,7 @@ def get_env_encodings(etype:str, valid_options:Iterable[str]=()) -> tuple[str,..
COMPRESS_FMT : str = COMPRESS_FMT_PREFIX+" with ratio %5.1f%% (%5iKB to %5iKB)"+COMPRESS_FMT_SUFFIX


ui_context : ContextManager = DummyContextManager()
ui_context : ContextManager = nullcontext()
if POSIX and not OSX:
from xpra.gtk_common.error import xlog
ui_context = xlog
Expand Down

0 comments on commit ae90878

Please sign in to comment.