Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6562591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:43:38+00:00 2026-05-25T13:43:38+00:00

When subclassing a base class, an inherited method is not working as expected. I’ve

  • 0

When subclassing a base class, an inherited method is not working as expected.

I’ve broken my module into a couple of pieces (sorry if this difficult to follow) all in a directory named Lan.

in Lan/__init__.py I have:

from Bridge import Bridge
from Ethernet import Ethernet

from BaseInterface import BaseInterface


def IfCtl(iftype):
    for cls in BaseInterface.__subclasses__():
        if iftype in cls.iftypes():
            return cls()
    raise ValueError

In Lan/Bridge.py

from Lan.BaseInterface import BaseInterface

class Bridge(BaseInterface):
    def __init__(self):
        BaseInterface.__init__(self)

    @staticmethod
    def iftypes():
        return ['br', 'bridge']

    def up(self):
        return 'Bringing up Bridge'

    def down(self):
        return 'Bringing down Bridge'

and finally in Lan/BaseInterface.py:

from time import sleep

class IfaceNotImplementedError(NotImplementedError):
    def __init__(self, methodName):
        self.methodName = methodName
    def __str__(self):
        return "Method %s must be subclassed" % self.methodName

class BaseInterface(object):
    @staticmethod
    def iftypes(): return ['']

    def up(self): raise IfaceNotImplementedError('up()')

    def down(self): raise IfaceNotImplementedError('down()')

    def restart(self, delay = 1.0):
        self.down()
        sleep(delay)
        self.up()

Everything seems to work as expected except the restart() method inherited from BaseInterface. The method appears to run because there is a pause when I run it, but I returns no data. I’d expect to see the text returned by the overwritten up() and down() methods.

>>> from Lan import IfCtl
>>> InterFace = IfCtl('br')
>>> print InterFace.down()
Bringing down Bridge
>>> print InterFace.up()
Bringing up Bridge
>>> print InterFace.restart()
None
>>> 

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:43:38+00:00Added an answer on May 25, 2026 at 1:43 pm

    Your restart() method does not return anything. If you want it to carry the return value of up you need the last line to read return self.up(). Otherwise, it will always return None like it is now – the default return for any function that does not have an explicit return value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If one can prevent subclassing by declaring private constructor in the base class, why
Without subclassing a UIResponder class(e.g. UIView) and overriding its touchesBegan:withEvent: method, is it possible
I'm not subclassing the control. Trying to trigger the event via Control.Size = Control.Size
Question about subclassing in matlab, under the new class system. I've got class A
I'm subclassing QProgressBar in a custom widget, and I overwrote the paintEvent method with
Lets say I have the following code: public class Base { // Some stuff
What are the consequences if you switch a model's base class from db.Model to
As mentioned in the Zend Framework manual , I created a base controller. Subclassing
When subclassing a base type, like float, is it possible to recalculate or reassign
In following code, I want to extend the behaviour of a class by deriving/subclassing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.