Skip to content

Commit af457d3

Browse files
debbiedubArneBab
authored andcommitted
Make sure mimetypes.guess_type always get a str argument
The change means that now calling mimetypes.guess_type is done with the argument type that mypy requires.
1 parent 454c19a commit af457d3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

fcp3/node.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3186,7 +3186,7 @@ def sha256dda(nodehelloid, identifier, path=None):
31863186
return hashlib.sha256(tohash).digest()
31873187

31883188

3189-
def guessMimetype(filename):
3189+
def guessMimetype(filename: str | bytes) -> tuple[str, str] | str:
31903190
"""
31913191
Returns a guess of a mimetype based on a filename's extension
31923192
"""
@@ -3197,10 +3197,16 @@ def guessMimetype(filename):
31973197
if filename.endswith(".tar.bz2"):
31983198
return ('application/x-tar', 'bzip2')
31993199
try:
3200-
m = mimetypes.guess_type(filename, False)[0]
3200+
m = mimetypes.guess_type(filename
3201+
if isinstance(filename, str)
3202+
else filename.decode(),
3203+
False)[0]
32013204
except TypeError: # bytes compared to string string …
32023205
try:
3203-
m = mimetypes.guess_type(filename.decode(), False)[0]
3206+
m = mimetypes.guess_type(filename.decode()
3207+
if isinstance(filename, bytes)
3208+
else filename,
3209+
False)[0]
32043210
except Exception:
32053211
m = None
32063212
except Exception:

0 commit comments

Comments
 (0)