C1W1 Question about File(...) in python


I’m going through the ungraded lab from the first week and I’m surprised at seeing this syntax:

def prediction(model: Model, file: UploadFile = File(...)):

I understand that the prediction function receives two parameters and the second parameter if of type UploadFile (a FastAPI format). But its default value File(...) doesn’t make sense to me. What do the three dots mean? Is this a FastAPI-specific format or a recent python change?


Please see this

1 Like

Thank you!

Thanks to your link, I learned that this is called Ellipsis in Python and has two main uses:

  • slicing in arrays all other dimensions not directly referenced
  • indicating in FastAPI that a parameter will be required

So file = File(...) means that the default value is a non-functional File argument, but it will work with a filled argument, something like File("mypicture.png").