Skip to content
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

Use typing_extensions only when needed #5331

Merged
merged 3 commits into from
Jun 24, 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
6 changes: 5 additions & 1 deletion beets/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
Union,
)

from typing_extensions import TypeAlias
if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

from unidecode import unidecode

from beets.util import hidden
Expand Down Expand Up @@ -157,7 +161,7 @@
"""Provide the canonical form of the path suitable for storing in
the database.
"""
path = syspath(path, prefix=False)

Check failure on line 164 in beets/util/__init__.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Incompatible types in assignment (expression has type "Union[str, bytes]", variable has type "bytes")
path = os.path.normpath(os.path.abspath(os.path.expanduser(path)))
return bytestring_path(path)

Expand All @@ -171,7 +175,7 @@

The argument should *not* be the result of a call to `syspath`.
"""
out = []

Check failure on line 178 in beets/util/__init__.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Need type annotation for "out" (hint: "out: List[<type>] = ...")
last_path = None
while path:
path = os.path.dirname(path)
Expand All @@ -188,17 +192,17 @@

def sorted_walk(
path: AnyStr,
ignore: Sequence = (),

Check failure on line 195 in beets/util/__init__.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Missing type parameters for generic type "Sequence"
ignore_hidden: bool = False,
logger: Optional[Logger] = None,
) -> Generator[Tuple, None, None]:

Check failure on line 198 in beets/util/__init__.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Missing type parameters for generic type "Tuple"
"""Like `os.walk`, but yields things in case-insensitive sorted,
breadth-first order. Directory and file names matching any glob
pattern in `ignore` are skipped. If `logger` is provided, then
warning messages are logged there when a directory cannot be listed.
"""
# Make sure the paths aren't Unicode strings.
path = bytestring_path(path)

Check failure on line 205 in beets/util/__init__.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

Incompatible types in assignment (expression has type "bytes", variable has type "str")
ignore = [bytestring_path(i) for i in ignore]

# Get all the directories and files at this level.
Expand All @@ -223,7 +227,7 @@
if fnmatch.fnmatch(base, pat):
if logger:
logger.debug(
"ignoring {} due to ignore rule {}".format(base, pat)

Check failure on line 230 in beets/util/__init__.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

If x = b'abc' then f"{x}" or "{}".format(x) produces "b'abc'", not "abc". If this is desired behavior, use f"{x!r}" or "{!r}".format(x). Otherwise, decode the bytes
)
skip = True
break
Expand All @@ -231,7 +235,7 @@
continue

# Add to output as either a file or a directory.
cur = os.path.join(path, base)

Check failure on line 238 in beets/util/__init__.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

No overload variant of "join" matches argument types "str", "bytes"
if (ignore_hidden and not hidden.is_hidden(cur)) or not ignore_hidden:
if os.path.isdir(syspath(cur)):
dirs.append(base)
Expand All @@ -245,7 +249,7 @@

# Recurse into directories.
for base in dirs:
cur = os.path.join(path, base)

Check failure on line 252 in beets/util/__init__.py

View workflow job for this annotation

GitHub Actions / Check types with mypy

No overload variant of "join" matches argument types "str", "bytes"
# yield from sorted_walk(...)
yield from sorted_walk(cur, ignore, ignore_hidden, logger)

Expand Down
7 changes: 6 additions & 1 deletion beetsplug/aura.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import os
import re
import sys
from dataclasses import dataclass
from mimetypes import guess_type
from typing import ClassVar, Mapping, Type
Expand All @@ -29,7 +30,11 @@
request,
send_file,
)
from typing_extensions import Self

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

from beets import config
from beets.dbcore.query import (
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For packagers:

* The minimum supported Python version is now 3.8.
* The `beet` script has been removed from the repository.
* The `typing_extensions` is required for Python 3.10 and below.

Other changes:

Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mediafile = ">=0.12.0"
munkres = ">=1.0.0"
musicbrainzngs = ">=0.4"
pyyaml = "*"
typing_extensions = "*"
typing_extensions = { version = "*", python = "<=3.10" }
unidecode = ">=1.3.6"
beautifulsoup4 = { version = "*", optional = true }
dbus-python = { version = "*", optional = true }
Expand Down
Loading