473,379 Members | 1,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

how about a builtin "abstractmethod"?

Python has a builtin class for staticmethod. Seems to me that Python
should also have a builtin class for abstractmethod. Something like
this...

#######################################

# simulated implementation of a new builtin class: abstractmethod
def abstractmethod(f):
methodName = f.__name__
def temp(self, *args, **kwargs):
raise NotImplementedError(
"Attempt to invoke unimplemented abstract method %s"
% methodName)
return temp

# example of using proposed builtin class: abstractmethod
class TestClass:
@abstractmethod
def TestMethod(self): pass
t = TestClass()
t.TestMethod() # call to abstract method raises exception
Jul 18 '05 #1
1 2129

st***@ferg.org (Stephen Ferg) wrote:
# simulated implementation of a new builtin class: abstractmethod
def abstractmethod(f):
methodName = f.__name__
def temp(self, *args, **kwargs):
raise NotImplementedError(
"Attempt to invoke unimplemented abstract method %s"
% methodName)
return temp

# example of using proposed builtin class: abstractmethod
class TestClass:
@abstractmethod
def TestMethod(self): pass

^^^^^
I don't believe that using a single line for such definitions are
considered Pythonic.
I prefer...

class TestClass:
def TestMethod(self):
raise NotImplementedError

Sure, you don't get the function name in your textual exception raise,
but you do get the function call in your traceback, and save yourself
having to use decorators when they are certainly not necessary, and
don't improve the readability nor understandability of the code.

- Josiah

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Noam Raphael | last post by:
Hello, I thought about a new Python feature. Please tell me what you think about it. Say you want to write a base class with some unimplemented methods, that subclasses must implement (or...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.