Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Problems trying to override __str__ on path class
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Peter Otten, post: 2041360"] From [URL]http://www.jorendorff.com/articles/python/path/changes.html[/URL]: """ This page describes recent changes to the Python path module. 2.1 [...] Better support for subclassing path. All methods that returned path objects now respect subclassing. Before: type(PathSubclass(s).parent) is path Now: type(PathSubclass(s).parent) is PathSubclass """ So my assumption was that you are using a pre-2.1 version of path. I suggest that you double-check that by inserting a print path.__version__ into the code showing the odd behaviour before you start looking for more exotic causes. For newstyle classes a = A() a / 42 # or any other operation implemented via __xxx__() (unlike a.__div__) will only look into the class for a __div__() special method and ignore methods defined in the instance or via the __getattr__() mechanism. For delegation to work you need (untested) class NormPath(object): def __div__(self, other): return self.__class__(self._path / other) # ... Peter [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Problems trying to override __str__ on path class
Top