Skip to content

Python 3.9 Modernization #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ $ pip install --user --upgrade --pre libtmux

<!-- To maintainers and contributors: Please add notes for the forthcoming version above -->

### Development

- Aggressive automated lint fixes via `ruff` (#550)

via ruff v0.8.4, all automated lint fixes, including unsafe and previews were applied for Python 3.9:

```sh
ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes; ruff format .
```

## libtmux 0.39.0 (2024-11-26)

_Maintenance only, no bug fixes or new features_
Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@pytest.fixture(autouse=True)
def add_doctest_fixtures(
request: pytest.FixtureRequest,
doctest_namespace: t.Dict[str, t.Any],
doctest_namespace: dict[str, t.Any],
) -> None:
"""Configure doctest fixtures for pytest-doctest."""
if isinstance(request._pyfuncitem, DoctestItem) and shutil.which("tmux"):
Expand Down
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
sys.path.insert(0, str(cwd / "_ext"))

# package data
about: t.Dict[str, str] = {}
about: dict[str, str] = {}
with (project_src / "libtmux" / "__about__.py").open() as fp:
exec(fp.read(), about)

Expand Down Expand Up @@ -71,8 +71,8 @@
html_css_files = ["css/custom.css"]
html_extra_path = ["manifest.json"]
html_theme = "furo"
html_theme_path: t.List[str] = []
html_theme_options: t.Dict[str, t.Union[str, t.List[t.Dict[str, str]]]] = {
html_theme_path: list[str] = []
html_theme_options: dict[str, t.Union[str, list[dict[str, str]]]] = {
"light_logo": "img/libtmux.svg",
"dark_logo": "img/libtmux.svg",
"footer_icons": [
Expand Down Expand Up @@ -138,7 +138,7 @@
}


def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:
def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]:
"""
Determine the URL corresponding to Python object.

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ build-backend = "hatchling.build"

[tool.mypy]
strict = true
python_version = "3.9"
files = [
"src",
"tests",
Expand Down Expand Up @@ -147,7 +148,7 @@ exclude_lines = [
]

[tool.ruff]
target-version = "py38"
target-version = "py39"

[tool.ruff.lint]
select = [
Expand Down
68 changes: 34 additions & 34 deletions src/libtmux/_internal/query_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class LookupProtocol(t.Protocol):

def __call__(
self,
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
data: t.Union[str, list[str], "Mapping[str, str]"],
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
"""Return callback for :class:`QueryList` filtering operators."""
...
Expand All @@ -43,7 +43,7 @@ class ObjectDoesNotExist(Exception):
def keygetter(
obj: "Mapping[str, t.Any]",
path: str,
) -> t.Union[None, t.Any, str, t.List[str], "Mapping[str, str]"]:
) -> t.Union[None, t.Any, str, list[str], "Mapping[str, str]"]:
"""Fetch values in objects and keys, supported nested data.

**With dictionaries**:
Expand Down Expand Up @@ -151,15 +151,15 @@ def parse_lookup(


def lookup_exact(
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
data: t.Union[str, list[str], "Mapping[str, str]"],
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
return rhs == data


def lookup_iexact(
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
data: t.Union[str, list[str], "Mapping[str, str]"],
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
if not isinstance(rhs, str) or not isinstance(data, str):
return False
Expand All @@ -168,8 +168,8 @@ def lookup_iexact(


def lookup_contains(
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
data: t.Union[str, list[str], "Mapping[str, str]"],
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
if not isinstance(rhs, str) or not isinstance(data, (str, Mapping, list)):
return False
Expand All @@ -178,8 +178,8 @@ def lookup_contains(


def lookup_icontains(
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
data: t.Union[str, list[str], "Mapping[str, str]"],
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
if not isinstance(rhs, str) or not isinstance(data, (str, Mapping, list)):
return False
Expand All @@ -193,8 +193,8 @@ def lookup_icontains(


def lookup_startswith(
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
data: t.Union[str, list[str], "Mapping[str, str]"],
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
if not isinstance(rhs, str) or not isinstance(data, str):
return False
Expand All @@ -203,8 +203,8 @@ def lookup_startswith(


def lookup_istartswith(
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
data: t.Union[str, list[str], "Mapping[str, str]"],
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
if not isinstance(rhs, str) or not isinstance(data, str):
return False
Expand All @@ -213,8 +213,8 @@ def lookup_istartswith(


def lookup_endswith(
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
data: t.Union[str, list[str], "Mapping[str, str]"],
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
if not isinstance(rhs, str) or not isinstance(data, str):
return False
Expand All @@ -223,17 +223,17 @@ def lookup_endswith(


def lookup_iendswith(
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
data: t.Union[str, list[str], "Mapping[str, str]"],
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
if not isinstance(rhs, str) or not isinstance(data, str):
return False
return data.lower().endswith(rhs.lower())


def lookup_in(
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
data: t.Union[str, list[str], "Mapping[str, str]"],
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
if isinstance(rhs, list):
return data in rhs
Expand All @@ -254,8 +254,8 @@ def lookup_in(


def lookup_nin(
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
data: t.Union[str, list[str], "Mapping[str, str]"],
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
if isinstance(rhs, list):
return data not in rhs
Expand All @@ -276,17 +276,17 @@ def lookup_nin(


def lookup_regex(
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
data: t.Union[str, list[str], "Mapping[str, str]"],
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
if isinstance(data, (str, bytes, re.Pattern)) and isinstance(rhs, (str, bytes)):
return bool(re.search(rhs, data))
return False


def lookup_iregex(
data: t.Union[str, t.List[str], "Mapping[str, str]"],
rhs: t.Union[str, t.List[str], "Mapping[str, str]", "re.Pattern[str]"],
data: t.Union[str, list[str], "Mapping[str, str]"],
rhs: t.Union[str, list[str], "Mapping[str, str]", "re.Pattern[str]"],
) -> bool:
if isinstance(data, (str, bytes, re.Pattern)) and isinstance(rhs, (str, bytes)):
return bool(re.search(rhs, data, re.IGNORECASE))
Expand Down Expand Up @@ -320,7 +320,7 @@ def __init__(self, op: str, *args: object) -> None:
return super().__init__(f"{op} not in LOOKUP_NAME_MAP")


class QueryList(t.List[T], t.Generic[T]):
class QueryList(list[T], t.Generic[T]):
"""Filter list of object/dictionaries. For small, local datasets.

*Experimental, unstable*.
Expand Down Expand Up @@ -475,7 +475,7 @@ class QueryList(t.List[T], t.Generic[T]):
def __init__(self, items: t.Optional["Iterable[T]"] = None) -> None:
super().__init__(items if items is not None else [])

def items(self) -> t.List[t.Tuple[str, T]]:
def items(self) -> list[tuple[str, T]]:
if self.pk_key is None:
raise PKRequiredException
return [(getattr(item, self.pk_key), item) for item in self]
Expand Down Expand Up @@ -531,19 +531,19 @@ def filter_lookup(obj: t.Any) -> bool:
return True

if callable(matcher):
_filter = matcher
filter_ = matcher
elif matcher is not None:

def val_match(obj: t.Union[str, t.List[t.Any], T]) -> bool:
def val_match(obj: t.Union[str, list[t.Any], T]) -> bool:
if isinstance(matcher, list):
return obj in matcher
return bool(obj == matcher)

_filter = val_match
filter_ = val_match
else:
_filter = filter_lookup
filter_ = filter_lookup

return self.__class__(k for k in self if _filter(k))
return self.__class__(k for k in self if filter_(k))

def get(
self,
Expand Down
Loading
Loading