Skip to content
Advertisement

Tag: instance

Type hint for instance of subclass

I want to allow type hinting using Python 3 to accept instances which are children of a given class. I’m using the enforce module to check the function typing. E.g.: but it seems like python 3 doesn’t allow for this syntax, returning: Argument ‘x’ was not of type < class ‘A’ >. Actual type was B. Any help? Answer By

How to get instance given a method of the instance?

Now can you get a reference to myInstance if you now only have access to methodReference? Answer If you are using Python 3: Otherwise: and by a similar token, for the class: For this kind of code discovery you should install iPython and use tab, for instance, in your case myReference.+TAB would give: Hence, you don’t need to worry about

Advertisement