Skip to content

Commit

Permalink
Fix 3.8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
scaramallion committed Jan 2, 2024
1 parent da53f83 commit f62a126
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 1 addition & 2 deletions pylibjpeg/tests/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def test_decode_bytes(self):

def test_unknown_decoder_type(self):
"""Test unknown decoder type."""
with pytest.raises(ValueError, match=r"Unknown decoder_type 'TEST'"):
get_decoders(decoder_type="TEST")
assert not get_decoders(decoder_type="TEST")


@pytest.mark.skipif(not RUN_JPEG, reason="No JPEG decoders available")
Expand Down
20 changes: 11 additions & 9 deletions pylibjpeg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
LOGGER = logging.getLogger(__name__)


DecodeSource = Union[str, os.PathLike[str], BinaryIO, bytes]
DecodeSource = Union[str, os.PathLike, BinaryIO, bytes]


class Decoder(Protocol):
Expand Down Expand Up @@ -127,10 +127,12 @@ def get_decoders(decoder_type: str = "") -> Dict[str, Decoder]:
"""
# TODO: Python 3.10 remove
if sys.version_info[:2] < (3, 10):
# {"package name": [EntryPoint(), ...]}
ep = metadata.entry_points()
if not decoder_type:
decoders = {}
for entry_point in DECODER_ENTRY_POINTS.values():
print(entry_point in ep)
if entry_point in ep:
decoders.update({val.name: val.load() for val in ep[entry_point]})

Expand All @@ -139,7 +141,7 @@ def get_decoders(decoder_type: str = "") -> Dict[str, Decoder]:
if decoder_type in ep:
return {val.name: val.load() for val in ep[decoder_type]}

raise ValueError(f"Unknown decoder_type '{decoder_type}'")
return {}

if not decoder_type:
decoders = {}
Expand All @@ -149,11 +151,11 @@ def get_decoders(decoder_type: str = "") -> Dict[str, Decoder]:

return decoders

try:
if decoder_type in DECODER_ENTRY_POINTS:
result = metadata.entry_points(group=DECODER_ENTRY_POINTS[decoder_type])
return {val.name: val.load() for val in result}
except KeyError:
raise ValueError(f"Unknown decoder_type '{decoder_type}'")

return {}


def get_pixel_data_decoders() -> Dict[str, Decoder]:
Expand Down Expand Up @@ -261,7 +263,7 @@ def get_encoders(encoder_type: str = "") -> Dict[str, Encoder]:
if encoder_type in ep:
return {val.name: val.load() for val in ep[encoder_type]}

raise ValueError(f"Unknown decoder_type '{encoders}'")
return {}

if not encoder_type:
encoders = {}
Expand All @@ -271,11 +273,11 @@ def get_encoders(encoder_type: str = "") -> Dict[str, Encoder]:

return encoders

try:
if encoder_type in ENCODER_ENTRY_POINTS:
result = metadata.entry_points().select(group=ENCODER_ENTRY_POINTS[encoder_type])
return {val.name: val.load() for val in result}
except KeyError:
raise ValueError(f"Unknown encoder_type '{encoder_type}'")

return {}


def get_pixel_data_encoders() -> Dict[str, Encoder]:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ show_error_codes = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_return_any = true
warn_unreachable = true
warn_unreachable = false
ignore_missing_imports = true
disallow_untyped_calls = true
disallow_untyped_defs = true
Expand Down

0 comments on commit f62a126

Please sign in to comment.