Skip to content

Commit 0d4f1fa

Browse files
Make all exceptions pickleable
1 parent 754b55a commit 0d4f1fa

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/
66

77
### 5.9.3 TBD
88
- Improved text of skipped file message to mention gitignore feature.
9+
- Made all exceptions pickleable.
910
- Fixed #1779: Pylama integration ignores pylama specific isort config overrides.
1011
- Fixed #1781: `--from-first` CLI flag shouldn't take any arguments.
1112
- Fixed #1785: `_ast` module incorrectly excluded from stdlib definition.

isort/exceptions.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""All isort specific exception classes should be defined here"""
2+
from functools import partial
23
from pathlib import Path
34
from typing import Any, Dict, List, Type, Union
45

@@ -8,6 +9,9 @@
89
class ISortError(Exception):
910
"""Base isort exception object from which all isort sourced exceptions should inherit"""
1011

12+
def __reduce__(self): # type: ignore
13+
return (partial(type(self), **self.__dict__), ())
14+
1115

1216
class InvalidSettingsPath(ISortError):
1317
"""Raised when a settings path is provided that is neither a valid file or directory"""
@@ -48,13 +52,14 @@ class FileSkipped(ISortError):
4852

4953
def __init__(self, message: str, file_path: str):
5054
super().__init__(message)
55+
self.message = message
5156
self.file_path = file_path
5257

5358

5459
class FileSkipComment(FileSkipped):
5560
"""Raised when an entire file is skipped due to a isort skip file comment"""
5661

57-
def __init__(self, file_path: str):
62+
def __init__(self, file_path: str, **kwargs: str):
5863
super().__init__(
5964
f"{file_path} contains a file skip comment and was skipped.", file_path=file_path
6065
)
@@ -63,7 +68,7 @@ def __init__(self, file_path: str):
6368
class FileSkipSetting(FileSkipped):
6469
"""Raised when an entire file is skipped due to provided isort settings"""
6570

66-
def __init__(self, file_path: str):
71+
def __init__(self, file_path: str, **kwargs: str):
6772
super().__init__(
6873
f"{file_path} was skipped as it's listed in 'skip' setting"
6974
" or matches a glob in 'skip_glob' setting",

tests/unit/test_exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pickle
2+
13
from isort import exceptions
24

35

@@ -8,6 +10,9 @@ def setup_class(self):
810
def test_init(self):
911
assert isinstance(self.instance, exceptions.ISortError)
1012

13+
def test_pickleable(self):
14+
assert isinstance(pickle.loads(pickle.dumps(self.instance)), exceptions.ISortError)
15+
1116

1217
class TestExistingSyntaxErrors(TestISortError):
1318
def setup_class(self):

0 commit comments

Comments
 (0)