On Thu, Apr 02, 2015 at 09:55:24PM +0200, Christian Boltz wrote:
> Am Donnerstag, 2. April 2015 schrieb Seth Arnold:
> > On Thu, Apr 02, 2015 at 12:03:40PM -0700, Steve Beattie wrote:
> > > > The difference is this:
> > > > 
> > > > $ python2.7 -c "print(len('   ')/2)"
> > > > 1
> 
> Seriously?
> 
> if 3/2 == 1:
>     print("old python inside")

To be fair, it's doing integer math when both the numerator and
denominator are integers; other things do this as well. Converting one
of them to a float makes the division operation return a float as well:

  $ python2.7 -c 'print(3/2)'
  1
  $ python2.7 -c 'print(3.0/2)'
  1.5

> > I think importing division from future makes sense here.
> Agreed. To make it more formal:
> 
> 
> Tell python2 about math
> 
> if 3/2 == 1:
>     print("python2 inside")
> 
> Add "from __future__ import division" so that python2 returns the
> correct result (if needed, as float)
> 
> On related news: At least python3 knows how to calculate correctly.
> 
> 
> I propose this patch for trunk and 2.9.

Acked-by: Steve Beattie <[email protected]> for both. Thanks.

> [ 21a-tell-python2-about-math.diff ]
> 
> === modified file utils/apparmor/aa.py
> --- utils/apparmor/aa.py        2015-04-02 12:01:55.401784901 +0200
> +++ utils/apparmor/aa.py        2015-04-02 21:34:02.886805899 +0200
> @@ -13,7 +13,7 @@
>  #
>  # 
> ----------------------------------------------------------------------
>  # No old version logs, only 2.6 + supported
> -from __future__ import with_statement
> +from __future__ import division, with_statement
>  import inspect
>  import os
>  import re
> 

-- 
Steve Beattie
<[email protected]>
http://NxNW.org/~steve/

Attachment: signature.asc
Description: Digital signature

-- 
AppArmor mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to