Pygments: Add return types for format/highlight.#6819
Pygments: Add return types for format/highlight.#6819Akuli merged 32 commits intopython:masterfrom Dreamsorcerer:patch-19
Conversation
|
These functions can return |
|
Yes, you're right. I was hoping to avoid needing to type the formatters as well. |
|
I'm not sure how to actually type that. You'd want |
|
Maybe it's possible to cheat a little. Maybe something with overloads like this? I'm sure this is wrong though: |
|
You are looking for self types: @overload
def __init__(self: Formatter[str], encoding: None = ...) -> None: ...
@overload
def __init__(self: Formatter[bytes], encoding: str) -> None: ... |
|
Yep, didn't think about doing that on the |
stubs/Pygments/pygments/__init__.pyi
Outdated
| @overload | ||
| def highlight(code, lexer, formatter, outfile: SupportsWrite[Any]) -> None: ... | ||
| @overload | ||
| def highlight(code, lexer, formatter, outfile: None = ...) -> str: ... |
There was a problem hiding this comment.
We should probably annotate the formatter argument here too.
Co-authored-by: Akuli <[email protected]>
Co-authored-by: Sam Bull <[email protected]>
|
OK, I think we're good now. |
No description provided.