File tree 4 files changed +54
-6
lines changed
4 files changed +54
-6
lines changed Original file line number Diff line number Diff line change 1
1
Changelog
2
2
=========
3
+ v3.10.1 (2023-03-22)
4
+ --------------------
5
+ - Handle pickle for :class: `filelock.Timeout ` :pr: `203 ` - by :user: `TheMatt2 `.
6
+
3
7
v3.10.0 (2023-03-15)
4
- -------------------
5
- - Add support for explicit file modes for lockfiles :pr: `192 - by :user:`jahrules `.
8
+ --------------------
9
+ - Add support for explicit file modes for lockfiles :pr: `192 ` - by :user: `jahrules `.
6
10
7
11
v3.9.1 (2023-03-14)
8
12
-------------------
9
13
- Use ``time.perf_counter `` instead of ``time.monotonic `` for calculating timeouts.
10
14
11
15
v3.9.0 (2022-12-28)
12
16
-------------------
13
- - Move build backend to ``hatchling `` :pr: `185 - by :user:`gaborbernat `.
17
+ - Move build backend to ``hatchling `` :pr: `185 ` - by :user: `gaborbernat `.
14
18
15
19
v3.8.1 (2022-12-04)
16
20
-------------------
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ line-length = 120
71
71
[tool .isort ]
72
72
profile = " black"
73
73
known_first_party = [" filelock" ]
74
+ add_imports = [" from __future__ import annotations" ]
74
75
75
76
[tool .mypy ]
76
77
python_version = " 3.11"
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
+ from typing import Any
4
+
3
5
4
6
class Timeout (TimeoutError ):
5
7
"""Raised when the lock could not be acquired in *timeout* seconds."""
6
8
7
9
def __init__ (self , lock_file : str ) -> None :
8
- #: The path of the file lock.
9
- self .lock_file = lock_file
10
+ super ().__init__ ()
11
+ self ._lock_file = lock_file
12
+
13
+ def __reduce__ (self ) -> str | tuple [Any , ...]:
14
+ return self .__class__ , (self ._lock_file ,) # Properly pickle the exception
10
15
11
16
def __str__ (self ) -> str :
12
- return f"The file lock '{ self .lock_file } ' could not be acquired."
17
+ return f"The file lock '{ self ._lock_file } ' could not be acquired."
18
+
19
+ def __repr__ (self ) -> str :
20
+ return f"{ self .__class__ .__name__ } ({ self .lock_file !r} )"
21
+
22
+ @property
23
+ def lock_file (self ) -> str :
24
+ """:return: The path of the file lock."""
25
+ return self ._lock_file
13
26
14
27
15
28
__all__ = [
Original file line number Diff line number Diff line change
1
+ from __future__ import annotations
2
+
3
+ import pickle
4
+
5
+ from filelock import Timeout
6
+
7
+
8
+ def test_timeout_str () -> None :
9
+ timeout = Timeout ("/path/to/lock" )
10
+ assert str (timeout ) == "The file lock '/path/to/lock' could not be acquired."
11
+
12
+
13
+ def test_timeout_repr () -> None :
14
+ timeout = Timeout ("/path/to/lock" )
15
+ assert repr (timeout ) == "Timeout('/path/to/lock')"
16
+
17
+
18
+ def test_timeout_lock_file () -> None :
19
+ timeout = Timeout ("/path/to/lock" )
20
+ assert timeout .lock_file == "/path/to/lock"
21
+
22
+
23
+ def test_timeout_pickle () -> None :
24
+ timeout = Timeout ("/path/to/lock" )
25
+ timeout_loaded = pickle .loads (pickle .dumps (timeout ))
26
+
27
+ assert timeout .__class__ == timeout_loaded .__class__
28
+ assert str (timeout ) == str (timeout_loaded )
29
+ assert repr (timeout ) == repr (timeout_loaded )
30
+ assert timeout .lock_file == timeout_loaded .lock_file
You can’t perform that action at this time.
0 commit comments