surplus: fix #17 (local codes must be full-length)

This commit is contained in:
Mark Joshwel 2023-09-01 14:44:50 +00:00
parent a7803ec3ca
commit fd372fb483

View file

@ -119,6 +119,10 @@ class NoSuitableLocationError(Exception):
... ...
class IncompletePlusCodeError(Exception):
...
# data structures # data structures
ResultType = TypeVar("ResultType") ResultType = TypeVar("ResultType")
@ -252,7 +256,7 @@ class PlusCodeQuery(NamedTuple):
except KeyError: except KeyError:
return Result[Latlong]( return Result[Latlong](
EMPTY_LATLONG, error="Plus Code is not full-length, e.g, 6PH58QMF+FX" EMPTY_LATLONG, error=IncompletePlusCodeError("Plus Code is not full-length (e.g., 6PH58QMF+FX)"),
) )
except Exception as exc: except Exception as exc:
@ -499,7 +503,14 @@ def parse_query(
if portion_plus_code == "": if portion_plus_code == "":
return Result[Query]( return Result[Query](
LatlongQuery(EMPTY_LATLONG), LatlongQuery(EMPTY_LATLONG),
error="unable to find a pluscode", error="unable to find a Plus Code",
)
# did find plus code, but not full-length. :(
if not validator.is_full(portion_plus_code):
return Result[Query](
LatlongQuery(EMPTY_LATLONG),
error=IncompletePlusCodeError("Plus Code is not full-length (e.g., 6PH58QMF+FX)"),
) )
# found a plus code! # found a plus code!
@ -546,6 +557,9 @@ def parse_query(
# found one! # found one!
return Result[Query](mpc_result.get()) return Result[Query](mpc_result.get())
if isinstance(mpc_result.error, IncompletePlusCodeError):
return mpc_result
match behaviour.query: match behaviour.query:
case [single]: case [single]:
# possibly a: # possibly a: