473,505 Members | 14,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ABC question: what is the purpose of the register() method?

I was reading PEP 3119 (http://www.python.org/dev/peps/pep-3119/ ) and
have done some experiments using Python 3.0a5. Now I'm somewhat
puzzled about the purpose of the ABCMeta.register() method.

One can use the register() method to register any class as a virtual
subclass of any ABC. For example one can register `int` on `Iterable`
and therefore it is a subclass which is confirmed in the issubclass
check. What is that good for?

This registration might even conflict with the implementation of
__subclasscheck__. So one might expect that register(C) leads to an
acceptance of a class as a subclass but this isnt't true if
__subclasscheck__(C) rejects it. Why isn't __subclasscheck__ not
sufficient?

Example:
--------------

class Interface(metaclass = ABCMeta):
@classmethod
def __subclasscheck__(cls, C):
return cls.__abstractmethods__.issubset(C.__dict__) # some
contract...

class IAppendable(Interface):
@abstractmethod
def append(self, item): pass
>>issubclass(list, IAppendable)
True
>>issubclass(tuple, IAppendable)
False
>>IAppendable.register(int)
issubclass(int, IAppendable)
False
>>import collections.Iterable as Iterable
Iterable.register(int)
issubclass(int, Iterable)
True

Jun 27 '08 #1
1 2080
On Jun 7, 1:37 pm, Kay Schluehr <kay.schlu...@gmx.netwrote:
I was reading PEP 3119 (http://www.python.org/dev/peps/pep-3119/) and
have done some experiments using Python 3.0a5. Now I'm somewhat
puzzled about the purpose of the ABCMeta.register() method.

One can use the register() method to register any class as a virtual
subclass of any ABC. For example one can register `int` on `Iterable`
and therefore it is a subclass which is confirmed in the issubclass
check. What is that good for?
It's mostly good for types created in C, where it's hard to inherit a
class. For example, builtin types register them selves under some ABCs
in collections.
Jun 27 '08 #2

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

Similar topics

1
14124
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
8
1695
by: Sue | last post by:
In this code why is it that when I press the SUBMIT button the focus only goes back to the Numeric field. What do I need to do to correct this problem? Sue <html>
9
1689
by: Matthew Polder | last post by:
Hi, When a class Apple is written and the assignment operator is not explicitly declared, the operator Apple& operator=(const Apple&) is created by the compiler. Is there any difference...
0
6414
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
4
261
by: TR | last post by:
MyPage.htm has <FORM ACTION="Register.aspx" METHOD="POST">. Where does Register.aspx reference the values passed to it via the Post method in MyPage.htm? Thanks in advance. TR
7
5135
by: int main(void) | last post by:
Hi all, I know that register variables work fine at block scope. I tried putting a register variable in file scope, like this, #include <stdio.h> register int a = 2; int main(void) {...
11
2839
by: manstey | last post by:
Hi, I am having trouble designing my classes. I have two classes. The first one wraps around an old-style class called oref Class CacheClass(object): def __init__(self, obj):
3
1205
by: Kevin Walzer | last post by:
I currently have a GUI application (using Tkinter) in which all the code is placed in a single script. This means that the GUI bits are a bit too tightly bound to the "under-the-hood" logic of the...
0
1111
by: ngxfer001 | last post by:
HI Experts, I am trying to learn VS Setup Project, the problem I experience now is, I have written a C++ program to register all my DirectShow filter by CreateProcess method. Q1: the reason I...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.