[issue13264] Monkeypatching using metaclass

2011-11-14 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Artem, if you have further information to make us reconsider this issue, please 
add a new message.

--
resolution:  - invalid
stage:  - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13264
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13264] Monkeypatching using metaclass

2011-11-12 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

It seems to me this is not a bug.  Closing?

--
nosy: +eric.araujo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13264
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13264] Monkeypatching using metaclass

2011-11-12 Thread Daniel Urban

Daniel Urban urban.dani...@gmail.com added the comment:

 It seems to me this is not a bug.

+1

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13264
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13264] Monkeypatching using metaclass

2011-10-25 Thread Artem Tomilov

New submission from Artem Tomilov scrapl...@gmail.com:

from abc import ABCMeta

class Meta(ABCMeta):
def __instancecheck__(cls, instance):
# monkeypatching class method
cls.__subclasscheck__ = super(Meta, cls).__subclasscheck__
return super(Meta, cls).__instancecheck__(instance)

def __subclasscheck__(cls, sub):
return cls in sub.mro()

class A(object):
__metaclass__ = Meta

class B(object): pass

# registering class 'B' as a virtual subclass of 'A'
A.register(B)

 issubclass(B, A)
False
 isinstance(B(), A) # = method __subclasscheck__ is now monkeypatched
True
 issubclass(B, A) # = desire to get 'True' because 'B' is a virtual subclass
False

--
components: None
messages: 146366
nosy: Artem.Tomilov
priority: normal
severity: normal
status: open
title: Monkeypatching using metaclass
type: behavior
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13264
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13264] Monkeypatching using metaclass

2011-10-25 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
nosy: +ezio.melotti

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13264
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13264] Monkeypatching using metaclass

2011-10-25 Thread Daniel Urban

Changes by Daniel Urban urban.dani...@gmail.com:


--
nosy: +durban

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13264
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13264] Monkeypatching using metaclass

2011-10-25 Thread Daniel Urban

Daniel Urban urban.dani...@gmail.com added the comment:

 class Meta(ABCMeta):
 def __instancecheck__(cls, instance):
 # monkeypatching class method
 cls.__subclasscheck__ = super(Meta, cls).__subclasscheck__

This line is approximately the same as:
cls.__dict__['__subclasscheck__'] = ...
So it will put the object in the namespace of cls. The function in the 
namespace of type(cls) will remain there. (Also, the object you put in there is 
a bound method, so this is probably not what you want.)


 return super(Meta, cls).__instancecheck__(instance)
 
 def __subclasscheck__(cls, sub):
 return cls in sub.mro()
 
 class A(object):
 __metaclass__ = Meta
 
 class B(object): pass
 
 # registering class 'B' as a virtual subclass of 'A'
 A.register(B)
 
  issubclass(B, A)
 False
  isinstance(B(), A) # = method __subclasscheck__ is now
 monkeypatched

A.__dict__['__subclasscheck__'] is now indeed the other method you put in 
there, but issubclass will call  type(A).__dict__['__subclasscheck__'] which 
remain the same. (Because __special__ methods a looked up directly in the 
namespace of the type of an object, see 
http://docs.python.org/dev/py3k/reference/datamodel#special-lookup).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue13264
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com