Closed ahankinson closed 2 years ago
I can make a PR, but would appreciate some direction: I can either make it raise on non-Pattern arguments, or change the function annotation to str
.
Yeah, I noticed that today actually.
I think ideally we would accept both by annotation and at runtime. IIRC, the strings are compiled in that register method.
If you are up for the challenge, I'd love to see a PR to fix.
The type annotation on
register_pattern
givesPattern
as the acceptable type.However, an exception is thrown if you do provide a pattern with
re.compile
, complaining that it must be astr
.So:
passes the type checker, but fails with an exception, while
does not raise an exception, but highlights the pattern argument as a mismatching type.
The relevant lines are:
https://github.com/sanic-org/sanic-routing/blob/main/sanic_routing/router.py#L241-L243
https://github.com/sanic-org/sanic-routing/blob/main/sanic_routing/router.py#L272-L276