Skip to content

Commit

Permalink
Make mypy happy.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalkrupinski committed Aug 25, 2024
1 parent 03800da commit da01e79
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions mimeparse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__license__ = 'MIT License'
__credits__ = ''

from typing import Dict, Generator, Iterable, Tuple
from typing import Dict, Generator, Iterable, Tuple, Union


class MimeTypeParseException(ValueError):
Expand Down Expand Up @@ -90,7 +90,7 @@ def parse_media_range(range: str) -> Tuple[str, str, Dict[str, str]]:
necessary.
"""
(type, subtype, params) = parse_mime_type(range)
params.setdefault('q', params.pop('Q', None)) # q is case insensitive
params.setdefault('q', params.pop('Q', '1.0')) # q is case insensitive
try:
if not params['q'] or not 0 <= float(params['q']) <= 1:
params['q'] = '1'
Expand All @@ -112,8 +112,8 @@ def quality_and_fitness_parsed(
match, or (-1, 0) if no match was found. Just as for quality_parsed(),
'parsed_ranges' must be a list of parsed media ranges.
"""
best_fitness = -1
best_fit_q = 0
best_fitness = -1.
best_fit_q: Union[float, str] = 0.
(target_type, target_subtype, target_params) = \
parse_media_range(mime_type)

Expand All @@ -128,10 +128,10 @@ def quality_and_fitness_parsed(
if type_match and subtype_match:

# 100 points if the type matches w/o a wildcard
fitness = type == target_type and 100 or 0
fitness = type == target_type and 100. or 0.

# 10 points if the subtype matches w/o a wildcard
fitness += subtype == target_subtype and 10 or 0
fitness += subtype == target_subtype and 10. or 0.

# 1 bonus point for each matching param besides "q"
param_matches = sum([
Expand Down

0 comments on commit da01e79

Please sign in to comment.