What's the purpose of the 2nd argument in this example code in the DataLoader docs?

I’m looking at the docs for the DataLoader class, and I see this example code:

class RandDL(DataLoader):
    def create_item(self, s):
        r = random.random()
        return r if r<0.95 else stop()

I see the 2 params to create_item are ‘self’ and ‘s’. I get the reason for the ‘self’ arg, but I don’t see ‘s’ used anywhere in the method body, so I’m confused as to why it’s included. I’m new to Python so I thought maybe ‘s’ is passed automatically somehow (like ‘self’ is), so I copied the above code into my Jupyter notebook, added ??s on the first line of the method, and ran the code. The result was TypeError: create_item() missing 1 required positional argument: 's', so I can deduce that it is not automatically passed.

My question is: does this 2nd param perform some function that I’m missing? And if not, what’s the purpose for including in this example code (and other examples as well)?

EDIT: I think I see what’s going on. Since RandDL subclasses DataLoader, there’s an expectation that the subclass’s version of create_item should have the same signature as the parent class’s implementation here. Still not able to decipher what s does in the parent class, but this is good enough for now.

1 Like