Skip to content

Commit

Permalink
fix: use if-else instead of match-case
Browse files Browse the repository at this point in the history
Structural Pattern Matching was only introduced in Python 3.10.
To maintain compatibility with older QGIS versions, result to if-else.
  • Loading branch information
koebi committed May 17, 2024
1 parent 7cb210c commit 5d9bc7e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 52 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ RELEASING:
14. Create new release in GitHub with tag version and release title of `vX.X.X`
-->

## Unreleased

### Fixed
- use if-else instead of structural pattern matching

## [1.8.0] - 2024-05-17

### Added
Expand Down
103 changes: 51 additions & 52 deletions ORStools/utils/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,55 +139,54 @@ def decode_extrainfo(extra_info: str, key: int) -> str | int:
">=16% incline",
]

match extra_info:
case "waytypes":
try:
return waytypes[key]
except IndexError:
return "Unknown"
case "surface":
try:
return surfaces[key]
except IndexError:
return "Unknown"
case "waycategory":
binary = list(bin(key))[2:]
padding = ["0"] * (len(waycategory) - len(binary))
padded_binary = padding + binary
category = ""

for set_bit, value in zip(padded_binary, waycategory):
if set_bit == "1":
category += value

if category == "":
return "No category"

return category
case "roadaccessrestrictions":
binary = list(bin(key))[2:]
padding = ["0"] * (len(restrictions) - len(binary))
padded_binary = padding + binary
restriction = ""

for set_bit, value in zip(padded_binary, restrictions):
if set_bit == "1":
restriction += value
restriction += " "

if restriction == "":
return "None"

return restriction
case "steepness":
# We get values from -5 to 5 here, but our decoded array is 11 values long.
key += 5
try:
return steepness[key]
except IndexError:
return "No steepness available"
case "traildifficulty":
# TODO: we need to differentiate the profile here…
return key
case _:
return key
if extra_info == "waytypes":
try:
return waytypes[key]
except IndexError:
return "Unknown"
elif extra_info == "surface":
try:
return surfaces[key]
except IndexError:
return "Unknown"
elif extra_info == "waycategory":
binary = list(bin(key))[2:]
padding = ["0"] * (len(waycategory) - len(binary))
padded_binary = padding + binary
category = ""

for set_bit, value in zip(padded_binary, waycategory):
if set_bit == "1":
category += value

if category == "":
return "No category"

return category
elif extra_info == "roadaccessrestrictions":
binary = list(bin(key))[2:]
padding = ["0"] * (len(restrictions) - len(binary))
padded_binary = padding + binary
restriction = ""

for set_bit, value in zip(padded_binary, restrictions):
if set_bit == "1":
restriction += value
restriction += " "

if restriction == "":
return "None"

return restriction
elif extra_info == "steepness":
# We get values from -5 to 5 here, but our decoded array is 11 values long.
key += 5
try:
return steepness[key]
except IndexError:
return "No steepness available"
elif extra_info == "traildifficulty":
# TODO: we need to differentiate the profile here…
return key
else:
return key

0 comments on commit 5d9bc7e

Please sign in to comment.