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

LudovicRousseau / pyscard / 16375184806

18 Jul 2025 04:07PM UTC coverage: 66.048% (+0.08%) from 65.964%
16375184806

push

github

LudovicRousseau
Fix pylint warning: R0401

smartcard/reader/Reader.py:1:0: R0401: Cyclic import (smartcard.pcsc.PCSCCardConnection -> smartcard.pcsc.PCSCPart10 -> smartcard.pcsc.PCSCReader) (cyclic-import)
smartcard/reader/Reader.py:1:0: R0401: Cyclic import (smartcard.pcsc.PCSCCardConnection -> smartcard.pcsc.PCSCReader) (cyclic-import)

103 of 481 branches covered (21.41%)

4445 of 6730 relevant lines covered (66.05%)

4.69 hits per line

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

100.0
/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
20✔
12

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

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

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

26

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

30

31
def synchronized(method: Callable[P, T]) -> Callable[P, T]:
20✔
32
    @functools.wraps(method)
20✔
33
    def f(self: _SynchronizationProtocol, *args: Any, **kwargs: Any) -> Any:
20✔
34
        with self.mutex:
19✔
35
            return method(self, *args, **kwargs)
19✔
36

37
    return f
20✔
38

39

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

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

51

52
class _SynchronizationProtocol(Protocol):
20✔
53
    mutex: threading.Lock | threading.RLock
20✔
54

55

56
class Synchronization(_SynchronizationProtocol):
20✔
57
    # You can create your own self.mutex, or inherit from this class:
58

59
    def __init__(self):
20✔
60
        self.mutex = threading.RLock()
19✔
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