How does "kwargs" is passed to a variable implicitly?

Question:

A simple code from pytorch tutorial, which is used to load the data
”’
tr_data = datasets.FashionMNIST(root="data", train=True, download=True, transform=ToTensor())
”’

enter image description here

However, when debug into the code as shown above. It use the "new" method without passing the "kwds". It seems the param "transform=ToTensor()" is never used, which in the result is not true. So I am wondering how the code processes the parameter, where-else is the kwds is read into a variable.

Asked By: Chris

||

Answers:

It’s checking to see if the superclass’s __new__ method is the same as object‘s. This can happen two ways: the superclass is object, or the superclass hasn’t overridden __new__ and neither have any of its superclasses back to object.

object doesn’t take any arguments in its constructor, so it doesn’t pass them if that’s the case. Since object doesn’t take any arguments, it also doesn’t need any, so the superclass call creates the object correctly.

After __new__ is called, __init__ is called. That is what actually initializes the object (as opposed to creating it). It needs to do something with the arguments, and likely does.

Answered By: kindall
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.