Skip to content

Commit a6dd0e6

Browse files
committed
Add lots of Typing for python >=3.12 and Modernize
1 parent 905e815 commit a6dd0e6

112 files changed

Lines changed: 7651 additions & 6099 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.flake8

Lines changed: 0 additions & 4 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@ coverage
1414
.hypothesis
1515
.pytest_cache
1616
.mypy_cache
17-
/poetry.lock
1817
/uv.lock

.mypy.ini

Lines changed: 0 additions & 9 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"python.languageServer": "None"
3+
// "python.languageServer": "None",
4+
// "python.analysis.typeCheckingMode": "off"
5+
}

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
source_suffix = '.rst'
2121
master_doc = 'index'
2222
project = 'mutagen'
23-
copyright = u'2016, Joe Wreschnig, Michael Urman, Lukáš Lalinský, ' \
24-
u'Christoph Reiter, Ben Ockmore & others'
23+
copyright = '2016, Joe Wreschnig, Michael Urman, Lukáš Lalinský, ' \
24+
'Christoph Reiter, Ben Ockmore & others'
2525
html_title = project
2626
exclude_patterns = ['_build']
2727

docs/id3_frames_gen.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
./id3_frames_gen.py > api/id3_frames.rst
1111
"""
1212

13-
import sys
1413
import os
14+
import sys
1515

1616
sys.path.insert(0, os.path.abspath('../'))
1717

1818
import mutagen.id3
19-
from mutagen.id3 import Frames, Frames_2_2, Frame
20-
19+
from mutagen.id3 import Frame, Frames, Frames_2_2
2120

2221
BaseFrames = dict([(k, v) for (k, v) in vars(mutagen.id3).items()
2322
if v not in Frames.values() and v not in Frames_2_2.values()
@@ -38,12 +37,12 @@ def print_frames(frames, sort_mro=False):
3837
else:
3938
sort_func = lambda x: x
4039

41-
for name, cls in sorted(frames.items(), key=sort_func):
42-
print("""
43-
.. autoclass:: mutagen.id3.%s
40+
for _name, cls in sorted(frames.items(), key=sort_func):
41+
print(f"""
42+
.. autoclass:: mutagen.id3.{repr(cls())}
4443
:show-inheritance:
4544
:members:
46-
""" % repr(cls()))
45+
""")
4746

4847

4948
if __name__ == "__main__":

docs/user/examples/fileobj-iface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class IOInterface(object):
1+
class IOInterface:
22
"""This is the interface mutagen expects from custom file-like
33
objects.
44

fuzzing/fuzztools.py

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
1+
import contextlib
2+
from collections.abc import Callable
13
from io import BytesIO
4+
from typing import Any
25

3-
from mutagen import File, Metadata
4-
from mutagen import MutagenError
6+
from mutagen import File, Metadata, MutagenError
7+
from mutagen.aac import AAC
8+
from mutagen.ac3 import AC3
9+
from mutagen.aiff import AIFF
10+
from mutagen.apev2 import APEv2, APEv2File
511
from mutagen.asf import ASF
6-
from mutagen.apev2 import APEv2File, APEv2
12+
from mutagen.dsdiff import DSDIFF
13+
from mutagen.dsf import DSF
14+
from mutagen.easyid3 import EasyID3, EasyID3FileType
15+
from mutagen.easymp4 import EasyMP4
716
from mutagen.flac import FLAC
8-
from mutagen.easyid3 import EasyID3FileType, EasyID3
9-
from mutagen.id3 import ID3FileType, ID3
10-
from mutagen.mp3 import MP3
11-
from mutagen.mp3 import EasyMP3
17+
from mutagen.id3 import ID3, ID3FileType
18+
from mutagen.monkeysaudio import MonkeysAudio
19+
from mutagen.mp3 import MP3, EasyMP3
20+
from mutagen.mp4 import MP4
21+
from mutagen.musepack import Musepack
1222
from mutagen.oggflac import OggFLAC
23+
from mutagen.oggopus import OggOpus
1324
from mutagen.oggspeex import OggSpeex
1425
from mutagen.oggtheora import OggTheora
1526
from mutagen.oggvorbis import OggVorbis
16-
from mutagen.oggopus import OggOpus
17-
from mutagen.trueaudio import EasyTrueAudio
18-
from mutagen.trueaudio import TrueAudio
19-
from mutagen.wavpack import WavPack
20-
from mutagen.easymp4 import EasyMP4
21-
from mutagen.mp4 import MP4
22-
from mutagen.musepack import Musepack
23-
from mutagen.monkeysaudio import MonkeysAudio
2427
from mutagen.optimfrog import OptimFROG
25-
from mutagen.aiff import AIFF
26-
from mutagen.aac import AAC
27-
from mutagen.ac3 import AC3
2828
from mutagen.smf import SMF
2929
from mutagen.tak import TAK
30-
from mutagen.dsf import DSF
30+
from mutagen.trueaudio import EasyTrueAudio, TrueAudio
3131
from mutagen.wave import WAVE
32-
from mutagen.dsdiff import DSDIFF
33-
32+
from mutagen.wavpack import WavPack
3433

3534
OPENERS = [
3635
MP3, TrueAudio, OggTheora, OggSpeex, OggVorbis, OggFLAC,
@@ -43,7 +42,7 @@
4342
# OPENERS = [AAC]
4443

4544

46-
def run(opener, f):
45+
def run(opener: Callable[[BytesIO], Any], f: BytesIO):
4746
try:
4847
res = opener(f)
4948
except MutagenError:
@@ -56,32 +55,28 @@ def run(opener, f):
5655
# These can still fail because we might need to parse more data
5756
# to rewrite the file
5857

59-
f.seek(0)
60-
try:
58+
_ = f.seek(0)
59+
with contextlib.suppress(MutagenError):
6160
res.save(f)
62-
except MutagenError:
63-
pass
6461

65-
f.seek(0)
62+
_ = f.seek(0)
6663
res = opener(f)
6764

68-
f.seek(0)
69-
try:
65+
_ = f.seek(0)
66+
with contextlib.suppress(MutagenError):
7067
res.delete(f)
71-
except MutagenError:
72-
pass
7368

7469
# These can also save to empty files
7570
if isinstance(res, Metadata):
7671
f = BytesIO()
7772
res.save(f)
78-
f.seek(0)
73+
_ = f.seek(0)
7974
opener(f)
80-
f.seek(0)
75+
_ = f.seek(0)
8176
res.delete(f)
8277

8378

84-
def run_all(data):
79+
def run_all(data: bytes):
8580
f = BytesIO(data)
8681
[run(opener, f) for opener in OPENERS]
8782

@@ -91,7 +86,7 @@ def group_crashes(result_path):
9186
and error type.
9287
"""
9388

94-
crash_paths = []
89+
crash_paths: list[str] = []
9590
pattern = os.path.join(result_path, '**', 'crashes', '*')
9691
for path in glob.glob(pattern):
9792
if os.path.splitext(path)[-1] == ".txt":
@@ -133,9 +128,9 @@ def norm_exc():
133128

134129

135130
if __name__ == '__main__':
136-
import sys
137131
import glob
138132
import os
139-
import traceback
133+
import sys
140134
import textwrap
135+
import traceback
141136
group_crashes(sys.argv[1])

fuzzing/sut.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2-
import sys
3-
import afl
42
import os
3+
import sys
54

5+
import afl
66
from fuzztools import run_all
77

88

@@ -15,7 +15,7 @@ def main():
1515
try:
1616
run_all(data)
1717
finally:
18-
buffer.seek(0)
18+
_ = buffer.seek(0)
1919

2020

2121
if __name__ == '__main__':

mutagen/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
for certain keys, again depending on format.
1919
"""
2020

21+
from mutagen._file import File, FileType, StreamInfo
22+
from mutagen._tags import Metadata, PaddingInfo, Tags
2123
from mutagen._util import MutagenError
22-
from mutagen._file import FileType, StreamInfo, File
23-
from mutagen._tags import Tags, Metadata, PaddingInfo
2424

2525
version = (1, 47, 1)
2626
"""Version tuple."""

0 commit comments

Comments
 (0)