Skip to content

Commit

Permalink
#1248: Use imp only when importlib.util not available
Browse files Browse the repository at this point in the history
The imp module is deprecated and will be removed in Python 12.
  • Loading branch information
scorphus committed Jul 10, 2023
1 parent 617aaa1 commit 0420442
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand Down
12 changes: 11 additions & 1 deletion thefuck/conf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
from imp import load_source
import os
import sys
from warnings import warn
from six import text_type
from . import const
from .system import Path

try:
import importlib.util

def load_source(name, pathname, _file=None):
module_spec = importlib.util.spec_from_file_location(name, pathname)
module = importlib.util.module_from_spec(module_spec)
module_spec.loader.exec_module(module)
return module
except ImportError:
from imp import load_source


class Settings(dict):
def __getattr__(self, item):
Expand Down
3 changes: 1 addition & 2 deletions thefuck/types.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from imp import load_source
import os
import sys
from . import logs
from .shells import shell
from .conf import settings
from .conf import settings, load_source
from .const import DEFAULT_PRIORITY, ALL_ENABLED
from .exceptions import EmptyCommand
from .utils import get_alias, format_raw_script
Expand Down

0 comments on commit 0420442

Please sign in to comment.