doc: fix build with python 3.8

Message ID 20191209210000.906000-1-thomas@monjalon.net (mailing list archive)
State Superseded, archived
Headers
Series doc: fix build with python 3.8 |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/travis-robot warning Travis build: failed

Commit Message

Thomas Monjalon Dec. 9, 2019, 9 p.m. UTC
  After upgrading to python-3.8.0, a syntax mismatch is revealed:

doc/guides/conf.py:240: SyntaxWarning: "is not" with a literal.
    Did you mean "!="?
    if value is not '':

Replacing "is not" with "!=" seems the right thing to do.

A patch may also be needed in the RTD theme package:
https://github.com/readthedocs/sphinx_rtd_theme/commit/a49a812c.diff
(not included in release 0.4.3)

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 doc/guides/conf.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Bruce Richardson Dec. 10, 2019, noon UTC | #1
On Mon, Dec 09, 2019 at 10:00:00PM +0100, Thomas Monjalon wrote:
> After upgrading to python-3.8.0, a syntax mismatch is revealed:
> 
> doc/guides/conf.py:240: SyntaxWarning: "is not" with a literal.
>     Did you mean "!="?
>     if value is not '':
> 
> Replacing "is not" with "!=" seems the right thing to do.
> 

Since this is basically just checking for an empty string is 
"len(value) > 0" not more logical than either comparison against ''?

/Bruce
  
Thomas Monjalon Dec. 10, 2019, 12:27 p.m. UTC | #2
10/12/2019 13:00, Bruce Richardson:
> On Mon, Dec 09, 2019 at 10:00:00PM +0100, Thomas Monjalon wrote:
> > After upgrading to python-3.8.0, a syntax mismatch is revealed:
> > 
> > doc/guides/conf.py:240: SyntaxWarning: "is not" with a literal.
> >     Did you mean "!="?
> >     if value is not '':
> > 
> > Replacing "is not" with "!=" seems the right thing to do.
> > 
> 
> Since this is basically just checking for an empty string is 
> "len(value) > 0" not more logical than either comparison against ''?

Probably yes.
I don't know what is the best practice in Python. Robin, any clue?
  
Robin Jarry Dec. 10, 2019, 1:33 p.m. UTC | #3
2019-12-10, Thomas Monjalon:
> 10/12/2019 13:00, Bruce Richardson:
> > On Mon, Dec 09, 2019 at 10:00:00PM +0100, Thomas Monjalon wrote:
> > > After upgrading to python-3.8.0, a syntax mismatch is revealed:
> > > 
> > > doc/guides/conf.py:240: SyntaxWarning: "is not" with a literal.
> > >     Did you mean "!="?
> > >     if value is not '':
> > > 
> > > Replacing "is not" with "!=" seems the right thing to do.
> > > 
> > 
> > Since this is basically just checking for an empty string is 
> > "len(value) > 0" not more logical than either comparison against ''?
> 
> Probably yes.
> I don't know what is the best practice in Python. Robin, any clue?

In most cases, it is shorter and cleaner to simply do:

  if value:

which behind the scenes calls value.__bool__() (or value.__len__()).

https://docs.python.org/3/reference/datamodel.html#object.__bool__
  
Thomas Monjalon Dec. 11, 2019, 10:58 a.m. UTC | #4
10/12/2019 14:33, Robin Jarry:
> 2019-12-10, Thomas Monjalon:
> > 10/12/2019 13:00, Bruce Richardson:
> > > On Mon, Dec 09, 2019 at 10:00:00PM +0100, Thomas Monjalon wrote:
> > > > After upgrading to python-3.8.0, a syntax mismatch is revealed:
> > > > 
> > > > doc/guides/conf.py:240: SyntaxWarning: "is not" with a literal.
> > > >     Did you mean "!="?
> > > >     if value is not '':
> > > > 
> > > > Replacing "is not" with "!=" seems the right thing to do.
> > > > 
> > > 
> > > Since this is basically just checking for an empty string is 
> > > "len(value) > 0" not more logical than either comparison against ''?
> > 
> > Probably yes.
> > I don't know what is the best practice in Python. Robin, any clue?
> 
> In most cases, it is shorter and cleaner to simply do:
> 
>   if value:
> 
> which behind the scenes calls value.__bool__() (or value.__len__()).
> 
> https://docs.python.org/3/reference/datamodel.html#object.__bool__

I guess it works also with python 2?

I am sending a v2 with this syntax, thanks.
  

Patch

diff --git a/doc/guides/conf.py b/doc/guides/conf.py
index e2b52e2df9..4575253c7b 100644
--- a/doc/guides/conf.py
+++ b/doc/guides/conf.py
@@ -237,7 +237,7 @@  def generate_overview_table(output_filename, table_id, section, table_name, titl
                                                                 ini_filename))
                 continue
 
-            if value is not '':
+            if value != '':
                 # Get the first letter only.
                 ini_data[ini_filename][name] = value[0]