In many discussions I have heard about Ruby in which people have expressed their reservations about the language, the issue of monkey patching comes up as one of their primary c
In Python, any literal (""
, {}
, 1.0
, etc) creates an instance of the standard class, even if you tried to monkeypatch it and redefined the corresponding class in your namespace.
It just won't work how you intended:
class str():
# define your custom string type
...
a = "foo" # still a real Python string
a = str("foo") # only this uses your custom class