Then a pointer can be generated and cast to the derived class for derived class functionality. Suppose a base class and a derived class exist, and that the "data" held by the base class is identical to the derived class - there is no "extra" sort of data in the derived class relative to the base class. ![]() Motivation aside, the need here is to upcast the base class instance to the inherited class instance. Please note that while the above is not some sort of ideal architecture, it is along the path to an ideal architecture having integrated old work from many authors with new work. The idea is to get this functioning so there are no circular imports and code parameters are all based on a single configuration without inducing tremendous change propagation in the code. I have also tried researching the question, but this seems to be a sticking point between the experts and the noobs, and there is no real good answer that actually confronts and addresses the issue directly. ![]() I have tried: from typing import cast cast(UpgradedFoo, foo), but that did not work. So winding back around to the impasse: upgraded_foo = UpgradedFoo(foo) # the c++-ish wayīut what is the way this is done in python? TheFoos.do_something_configured_just_once_in_new_code() Upgraded_foo = UpgradedFoo(foo) # the pythonic pseudo code of the C++ wayĪnd in a large variety of downstream files: from import upgraded_fooĪnd a large variety of legacy files: from import TheFoos # descendant class with useful methods in UpgradedFoo.pyįinally, the crux of the question: # interface for end user interface.py # classes since it is a configured entity ![]() # it is also useful to import and use early prior to the interpretation of other # a class that is difficult to construct, as it is connected to configuration
0 Comments
Leave a Reply. |