How to use Ellipsis as function argument default
After reading this Q&A, I decided to try using Ellipsis as a function argument default: def func(arg: int = ...): print(arg) However, Pyright complains: Expression of type "EllipsisType" cannot be assigned to parameter of type "int" "EllipsisType" is not assignable to "int" Because ... isn't an int. So I tried using a Union: def func(arg: int | Ellipsis = ...): print(arg) Pyright still complains: Variable not allowed in type expression (variable) Ellipsis: Unknown It only works if the function body is a literal Ellipsis (not print(arg) or even pass): def func(arg: int = ...): # happy pyright!
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.