title: How to subclass str in Python
body: <p>I am trying to subclass str object, and add couple of methods to it. My main purpose is to learn how to do it. Where I am stuck is, am I supposed to subclass string in a metaclass, and create my class with that meta, or subclass str directly? </p>
  
  <p>And also, I guess I need to implement <code>__new__()</code> somehow, because, my custom methods will modify my string object, and will return new mystr obj. </p>
  
  <p>My class's methods, should be completely chainable with str methods, and should always return a new my class instance when custom methods modified it. I want to be able to do something like this:</p>
  
  <pre><code>a = mystr("something")
  b = a.lower().mycustommethod().myothercustommethod().capitalize()
  issubclass(b,mystr) # True
  </code></pre>
  
  <p>I want to have it all the abilities that a <code>str</code> have. For example, <code>a = mystr("something")</code> then I want to use it like, 
     a.capitalize().mycustommethod().lower()</p>
  
  <p>It is my understanding that, I need to implement <code>__new__()</code>. I think so because, strings methods would probably try to create new str instances. So , if I overwrite <code>__new__()</code>, They supposedly would return my custom str class. However, I don't know how to pass arguments to my custom class's <code>__init__()</code> method in that case. And I guess I would need to use <code>type()</code> in order to create a new instance in <code>__new__()</code> method right?</p>