roadlabs / cefpython

Automatically exported from code.google.com/p/cefpython
0 stars 0 forks source link

Use a bit more pythonic way to compare versions #53

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently there are lot of code such this:

    if sys.hexversion >= 0x02070000 and sys.hexversion < 0x03000000:
        import cefpython_py27 as cefpython
    elif sys.hexversion >= 0x03000000 and sys.hexversion < 0x04000000:
        import cefpython_py32 as cefpython

With python's chained comparisons this can also be rendered as this:

    if 0x02070000 <= sys.hexversion < 0x03000000:
        import cefpython_py27 as cefpython
    elif 0x03000000 <= sys.hexversion < 0x04000000:
        import cefpython_py32 as cefpython
    else:
        raise Exception("Unsupported python version: %s" % sys.version)

http://docs.python.org/2/reference/expressions.html#not-in

Rather pointless patch, but anyway...

Original issue reported on code.google.com by madisli...@gmail.com on 1 Apr 2013 at 1:29

Attachments:

GoogleCodeExporter commented 9 years ago
At first it looks like a Yoda Condition [1]. A range may be presented
in such a way in mathematics, but I'm not sure if it's appropriate for
a programming, it doesn't feel natural.

[1] http://www.codinghorror.com/blog/2012/07/new-programming-jargon.html

Original comment by czarek.t...@gmail.com on 1 Apr 2013 at 1:48

GoogleCodeExporter commented 9 years ago
But python interpreter doesn't have to access sys.hexversion twice (but of 
course this isn't really a problem :)). 

I think you're just not used to see something like that. It's something that 
can't be argued, as it's highly subjective. So I'm absolutely fine if you don't 
apply this patch.

Original comment by madisli...@gmail.com on 1 Apr 2013 at 2:05

GoogleCodeExporter commented 9 years ago
After a second thought I started liking it :-)
All example scripts have been updated, see revision 384423831441.

Original comment by czarek.t...@gmail.com on 7 May 2013 at 7:43