Extract superclass
The Extract Superclass refactoring lets you create a superclass for an existing class.
The members of the original class can be moved to the superclass. For a method, you can transfer only the method declaration but not the implementation, declaring the method as abstract in the superclass. As a result, you will have a superclass and the original class inheriting from the superclass.
Extract a superclass
Place the caret inside a class in the editor.
Choose
from the main menu or from the context menu.In the Extract Superclass dialog, specify the following:
Name of the new superclass in the Extract superclass from field.
Target file where the new superclass will be stored in the Extract superclass with members to directory field.
Select the members of the class to be included in the superclass in Extract superclass from.
If you want the methods in the superclass to be abstract, select the Make Abstract checkbox.
The Extract superclass from field displays the name of the class, from which a superclass should be extracted. It is read-only.
Click Preview to check the refactoring result before proceeding. PyCharm will notify you in case of problems.
Click Extract to proceed with the refactoring. PyCharm will create a superclass and modify the original class to inherit from it :