derived-class

mypy complains about extended base class' attribute type

mypy complains about extended base class' attribute type Question: I have two base classes A and B that are defined like this: class A(object): def common_function(self): pass class B(object): def __init__(self, a: A): self.a = a def another_common_function(self): pass Class A holds some management information, whereas class B holds some other information, which is based …

Total answers: 2

how to get derived class name from base class

how to get derived class name from base class Question: I have a base class Person and derived classes Manager and Employee. Now, what I would like to know is the object created is Manager or the Employee. The person is given as belows: from Project.CMFCore.utils import getToolByName schema = getattr(Person, ‘schema’, Schema(())).copy() + Schema((TextField(‘FirstName’, …

Total answers: 7

Cast base class to derived class python (or more pythonic way of extending classes)

Cast base class to derived class python (or more pythonic way of extending classes) Question: I need to extend the Networkx python package and add a few methods to the Graph class for my particular need The way I thought about doing this is simplying deriving a new class say NewGraph, and adding the required …

Total answers: 9