Skip to content

How to make Pylance take into account decorators? #9661

Answered by erictraut
baruchli asked this question in Q&A
Discussion options

You must be logged in to vote

It's difficult for me to understand the problem based on the code you've provided. The code is not properly formatted and contains a bunch of symbols that are undefined. For example, I don't know how the Update class is defined. I'm guessing that callback_query is an attribute or property whose type is declared as Callable | None or something like that. If my assumption is correct, then the answer is no, the Python type system doesn't provide a way for one function (the decorator) to tell another function (the decorated function) that "I've tested this attribute within this object, and it is not None". You would need to add an assert in the code within the decorated function to handle this.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@baruchli
Comment options

@erictraut
Comment options

Answer selected by baruchli
@baruchli
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants