• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LudovicRousseau / pyscard / 18294779822

06 Oct 2025 09:20PM UTC coverage: 64.978% (-0.02%) from 64.994%
18294779822

push

github

web-flow
[pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/pre-commit/pre-commit-hooks: v5.0.0 → v6.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v5.0.0...v6.0.0)
- [github.com/psf/black-pre-commit-mirror: 25.1.0 → 25.9.0](https://github.com/psf/black-pre-commit-mirror/compare/25.1.0...25.9.0)
- [github.com/pycqa/isort: 6.0.1 → 6.1.0](https://github.com/pycqa/isort/compare/6.0.1...6.1.0)
- [github.com/python-jsonschema/check-jsonschema: 0.33.2 → 0.34.0](https://github.com/python-jsonschema/check-jsonschema/compare/0.33.2...0.34.0)

106 of 475 branches covered (22.32%)

4065 of 6256 relevant lines covered (64.98%)

4.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.43
/src/smartcard/Synchronization.py
1
"""
2
from Thinking in Python, Bruce Eckel
3
https://python-3-patterns-idioms-test.readthedocs.io/en/latest/Observer.html
4

5
(c) Copyright 2008, Creative Commons Attribution-Share Alike 3.0.
6

7
Simple emulation of Java's 'synchronized'
8
keyword, from Peter Norvig.
9
"""
10

11
from __future__ import annotations
19✔
12

13
import functools
19✔
14
import sys
19✔
15
import threading
19✔
16
from collections.abc import Iterable
19✔
17
from typing import Any, Callable, Protocol, TypeVar
19✔
18

19
# pylint: disable=too-few-public-methods
20

21
if sys.version_info >= (3, 10):
19✔
22
    from typing import ParamSpec
19✔
23
else:
24
    from typing_extensions import ParamSpec
×
25

26

27
T = TypeVar("T")
19✔
28
P = ParamSpec("P")
19✔
29

30

31
def synchronized(method: Callable[P, T]) -> Callable[P, T]:
19✔
32
    """Synchronize methods with the same mutex"""
33

34
    @functools.wraps(method)
19✔
35
    def f(self: _SynchronizationProtocol, *args: Any, **kwargs: Any) -> Any:
19✔
36
        with self.mutex:
17✔
37
            return method(self, *args, **kwargs)
17✔
38

39
    return f
19✔
40

41

42
def synchronize(klass: type, names: str | Iterable[str] | None = None) -> None:
19✔
43
    """Synchronize methods in the given class.
44
    Only synchronize the methods whose names are
45
    given, or all methods if names=None."""
46

47
    if isinstance(names, str):
19✔
48
        names = names.split()
19✔
49
    for name, val in list(klass.__dict__.items()):
19✔
50
        if callable(val) and name != "__init__" and (names is None or name in names):
19✔
51
            setattr(klass, name, synchronized(val))
19✔
52

53

54
class _SynchronizationProtocol(Protocol):
19✔
55
    mutex: threading.Lock | threading.RLock
19✔
56

57

58
class Synchronization(_SynchronizationProtocol):
19✔
59
    """You can create your own self.mutex, or inherit from this class"""
60

61
    def __init__(self):
19✔
62
        self.mutex = threading.RLock()
17✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc