Skip to content

Commit

Permalink
Handle new collections.abc imports through the compat module
Browse files Browse the repository at this point in the history
  • Loading branch information
dlax committed Feb 21, 2024
1 parent fa9e5c3 commit 26f2d4a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
3 changes: 2 additions & 1 deletion pgactivity/activities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import builtins
import os
import time
from typing import Sequence, TypeVar
from typing import TypeVar
from warnings import catch_warnings, simplefilter

import attr
import psutil

from .compat import Sequence
from .types import (
BlockingProcess,
IOCounter,
Expand Down
36 changes: 36 additions & 0 deletions pgactivity/compat.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
from __future__ import annotations

import operator
import sys
from importlib.metadata import version
from typing import Any

import attr
import attr.validators
import blessed

__all__ = [
"Callable",
"Dict",
"Iterable",
"Iterator",
"Mapping",
"MutableSet",
"Sequence",
"Tuple",
]

if sys.version_info >= (3, 9):
from collections.abc import (
Callable,
Iterable,
Iterator,
Mapping,
MutableSet,
Sequence,
)

Dict = dict
Tuple = tuple # type: ignore[type-arg]
else:
from typing import (
Callable,
Dict,
Iterable,
Iterator,
Mapping,
MutableSet,
Sequence,
Tuple,
)

ATTR_VERSION = tuple(int(x) for x in version("attrs").split(".", 2)[:2])
BLESSED_VERSION = tuple(int(x) for x in version("blessed").split(".", 2)[:2])

Expand Down
4 changes: 3 additions & 1 deletion pgactivity/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import logging
import os
from typing import Any, Callable, Dict, Sequence, TypeVar, overload
from typing import Any, TypeVar, overload

from .compat import Callable, Dict, Sequence

Row = TypeVar("Row")

Expand Down
15 changes: 2 additions & 13 deletions pgactivity/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,14 @@
import functools
from datetime import timedelta
from ipaddress import IPv4Address, IPv6Address
from typing import (
Any,
Callable,
Iterable,
Iterator,
Mapping,
MutableSet,
Sequence,
Tuple,
TypeVar,
Union,
overload,
)
from typing import Any, TypeVar, Union, overload

import attr
import psutil
from attr import validators

from . import colors, compat, pg, utils
from .compat import Callable, Iterable, Iterator, Mapping, MutableSet, Sequence, Tuple
from .config import Configuration, Flag


Expand Down
4 changes: 2 additions & 2 deletions pgactivity/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import inspect
import itertools
from textwrap import TextWrapper, dedent
from typing import Any, Callable, Iterable, Iterator, Sequence
from typing import Any

from blessed import Terminal

from . import colors, utils
from .activities import sorted as sorted_processes
from .compat import link
from .compat import Callable, Iterable, Iterator, Sequence, link
from .keys import BINDINGS, EXIT_KEY
from .keys import HELP as HELP_KEY
from .keys import (
Expand Down

0 comments on commit 26f2d4a

Please sign in to comment.