-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pygments: Add return types for format/highlight. #6819
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 |
Co-authored-by: Akuli <akuviljanen17@gmail.com>
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably annotate the formatter
argument here too.
Co-authored-by: Akuli <akuviljanen17@gmail.com>
Co-authored-by: Sam Bull <aa6bs0@sambull.org>
OK, I think we're good now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
No description provided.