top | item 47209508

(no title)

IshKebab | 6 hours ago

I think it would be worth mentioning that in normal use (strict mode) Pyright simply requires you to add type annotations to the declaration. Occasionally mildly annoying but IMO it's clearly the best option.

discuss

order

veber-alex|3 hours ago

It's not "mildly annoying".

I don't enable strict mode on multiple projects because people don't want to type anything outside of function signatures.

Inferring the type from the first use is 100% the correct choice because this is what users want 99% of the time, for the rest you can provide type information.

maleldil|1 hour ago

Annotating empty collections is one of the few places you need to annotate outside function signatures. It's not a big deal. It doesn't happen that often.

ocamoss|2 hours ago

Requiring the annotations on empty containers is the only way to have type safety if the type checker cannot infer the type of the container, like Pyright.

If the type checker can infer a type then the annotation would only be required if the inferred type doesn't match the user's intent, which means one would need to add fewer annotations to an arbitrary working-but-unannotated program to satisfy the type checker.