Conversation
inspect.formatannotation by replacing reinspect.formatannotation by replacing re
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
AA-Turner
left a comment
There was a problem hiding this comment.
I'm less sure this is worth it, the replacement isn't clearly better maintenence-wise.
What do the benchmarks look like if you extract repl to a module-level _formatannotation_repl and use .sub() on a pre-compiled pattern?
A
|
Out of curiosity, why use the little replace dance in the refactored code instead of just |
- Union[typing.List[str], typing.Dict[str, typing.Any]]
+ Union[List[str], Dict[str, Any]]The For what it’s worth: pat = re.compile(r"\b(?<!\.)typing\.")
pat.sub("", repr(annotation)) |

timeitbenchmark with my script:inspect_bench.py:Result: 2.0s -> 1.18s = x1.74 as fast
reuses #130167