Skip to content

Commit

Permalink
Make all exceptions pickleable
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Jul 24, 2021
1 parent 754b55a commit 0d4f1fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/

### 5.9.3 TBD
- Improved text of skipped file message to mention gitignore feature.
- Made all exceptions pickleable.
- Fixed #1779: Pylama integration ignores pylama specific isort config overrides.
- Fixed #1781: `--from-first` CLI flag shouldn't take any arguments.
- Fixed #1785: `_ast` module incorrectly excluded from stdlib definition.
Expand Down
9 changes: 7 additions & 2 deletions isort/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""All isort specific exception classes should be defined here"""
from functools import partial
from pathlib import Path
from typing import Any, Dict, List, Type, Union

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

def __reduce__(self): # type: ignore
return (partial(type(self), **self.__dict__), ())


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

def __init__(self, message: str, file_path: str):
super().__init__(message)
self.message = message
self.file_path = file_path


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

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

def __init__(self, file_path: str):
def __init__(self, file_path: str, **kwargs: str):
super().__init__(
f"{file_path} was skipped as it's listed in 'skip' setting"
" or matches a glob in 'skip_glob' setting",
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pickle

from isort import exceptions


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

def test_pickleable(self):
assert isinstance(pickle.loads(pickle.dumps(self.instance)), exceptions.ISortError)


class TestExistingSyntaxErrors(TestISortError):
def setup_class(self):
Expand Down

0 comments on commit 0d4f1fa

Please sign in to comment.