Extract the substring the match flagged. language_tool_python returns m.context (the snippet) and m.offsetInContext / m.errorLength. The flagged token is at m.context[offsetInContext:offsetInContext+errorLength].
(m)
| 492 | |
| 493 | |
| 494 | def _flagged_text(m): |
| 495 | """Extract the substring the match flagged. |
| 496 | |
| 497 | language_tool_python returns m.context (the snippet) and |
| 498 | m.offsetInContext / m.errorLength. The flagged token is at |
| 499 | m.context[offsetInContext:offsetInContext+errorLength]. |
| 500 | """ |
| 501 | ctx = _attr(m, "context", default="") or "" |
| 502 | off = _attr(m, "offset_in_context", "offsetInContext", default=0) or 0 |
| 503 | length = _attr(m, "error_length", "errorLength", default=0) or 0 |
| 504 | return ctx[off:off + length] |
| 505 | |
| 506 | |
| 507 | def _attr(obj, *names, default=None): |
no test coverage detected