If I do something like this :
from mailbox import Mailbox
Mailbox.get = 'dummy'
There is no error, I just replaced the get method.
But if I do a :
from datetime import datetime
datetime.now = 'dummy'
I get :
TypeError: can't set attributes of built-in/extension type 'datetime.datetime'
This is strange because the source code is readable at /usr/lib/python3.6/datetime.py.
I guess this library has been compiled for performance reason, that is why it cannot be modified. But, then, the question is : how I can know a class is immutable because it is built-in or an extension (without just testing like I did) ? why can I patch Mailbox class and not datetime class ?