[MERGE] bzrlib.osutils fixes

Andrew Bennetts andrew at canonical.com
Sun Mar 11 01:40:38 GMT 2007


Robert Collins wrote:
[...]
> 
> Theres another possible with with using named variables; we have a bit
> of an ugly smell around file kinds at the moment: they are strings, and
> you call functions to get things related to those strings. The actual
> strings are rarely printed anywhere though.
> 
> Perhaps we could instead have:
> 
> class PathKind(object):
>     
>     def __init__(self, marker, versionable):
>         self.marker = marker
>         self.versionable = versionable
> 
> 
> kind_directory = PathKind('/', True)
> kind_file = PathKind('', True)
> kind_link = PathKind('@', True)
> kind_socket = PathKind('$', False)
> ...
> 
> 'foo is kind_directory' will work, as will 'foo is not kind_directory'
> and 'foo in (kind_directory, kind_file)' etc.

(Don't you wish python had a "is in" operator?  I know I do sometimes...)

This looks like a good solution.  The "is" operator should be just as fast
regardless of the type of object involved (it's just comparing two pointers,
basically), and having the 'marker' and 'versionable' attributes sounds like a
good readability win.

-Andrew.




More information about the bazaar mailing list