nicfit / eyeD3

eyeD3 is a Python module and command line program for processing ID3 tags. Information about mp3 files (i.e bit rate, sample frequency, play time, etc.) is also provided. The formats supported are ID3v1 (1.0/1.1) and ID3v2 (2.3/2.4).
http://eyed3.nicfit.net/
GNU General Public License v3.0
536 stars 58 forks source link

Circular import v0.9.5 python3.9 #511

Closed Nathoufresh closed 3 years ago

Nathoufresh commented 3 years ago

Hello, my linux distro Manjaro updated python to 3.9 since then I have a circular import issue.

audiofile = eyed3.load(path) causes

File "/usr/lib/python3.9/site-packages/eyed3/core.py", line 72, in load
from .mimetype import guessMimetype
ImportError: cannot import name 'guessMimetype' from partially initialized module 'eyed3.mimetype' (most likely due to a circular import) (/usr/lib/python3.9/site-packages/eyed3/mimetype.py)

I "fixed" it by adding import eyed3.mimetype before from .mimetype import guessMimetype in eyed3/core.py

nicfit commented 3 years ago

Hmm, odd. Does this patch accomplish the same success for you?

diff --git a/eyed3/core.py b/eyed3/core.py
index 0ea9992..d86793d 100644
--- a/eyed3/core.py
+++ b/eyed3/core.py
@@ -422,8 +422,7 @@ def load(path, tag_version=None) -> AudioFile:
     metadata is loaded. This value must be a version constant specific to the
     eventual format of the metadata.
     """
-    from . import mp3, id3
-    from .mimetype import guessMimetype
+    from . import mimetype, mp3, id3

     if not isinstance(path, pathlib.Path):
         path = pathlib.Path(path)
@@ -435,7 +434,7 @@ def load(path, tag_version=None) -> AudioFile:
     else:
         raise IOError(f"file not found: {path}")

-    mtype = guessMimetype(path)
+    mtype = mimetype.guessMimetype(path)
     log.debug(f"File mime-type: {mtype}")

     if mtype in mp3.MIME_TYPES:
Nathoufresh commented 3 years ago

Yes works well now!