-
I have a function like this: def get_pictures()->dict:
return {
'items': [OnlineIterm(i,self.req) for i in pageInfo['list']],
'has_more': pageInfo['has_more'],
'cursor': pageInfo['cursor'],
} As you see, the result of get_pictures has exactly type: { as you see, the type of pic is unknown. How do I make it's type be List[OnlineIterm] ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The return type of In this case, you could declare the return type as If you want your dictionaries to have a different type for each specified key value, you should define a |
Beta Was this translation helpful? Give feedback.
The return type of
get_pictures
is annotated asdict
. Thedict
class is a generic class that accepts two type arguments, but you have provided neither of them in the type annotation. When type arguments are omitted, PEP 484 indicates that type checkers should assume that they areAny
. Pyright distinguishes between explicitAny
and implicitAny
with the latter form referred to asUnknown
. So you have effectively declared that the return type ofget_pictures
isdict[Unknown, Unknown]
— i.e. a dictionary with keys and values of any type.In this case, you could declare the return type as
dict[str, Any]
ordict[str, list[Sequence[OnlineIterm] | bool | str]
.If you want your dictionaries to ha…