cooker: avoid DeprecationWarning with python-3.11

Message ID 20220608085733.73997-1-Martin.Jansa@gmail.com
State New
Headers show
Series cooker: avoid DeprecationWarning with python-3.11 | expand

Commit Message

Martin Jansa June 8, 2022, 8:57 a.m. UTC
* fixes:
  bitbake/lib/bb/cooker.py:16: DeprecationWarning: module 'sre_constants' is deprecated
  import sre_constants

  it's deprecated since 3.11 with:
  https://github.com/python/cpython/issues/91308

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
 lib/bb/cooker.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Alexander Kanavin June 8, 2022, 9:54 a.m. UTC | #1
Neither the old or the new is a documented item, so I believe it is
better to eliminate the use entirely?

Alex

On Wed, 8 Jun 2022 at 10:57, Martin Jansa <Martin.Jansa@gmail.com> wrote:
>
> * fixes:
>   bitbake/lib/bb/cooker.py:16: DeprecationWarning: module 'sre_constants' is deprecated
>   import sre_constants
>
>   it's deprecated since 3.11 with:
>   https://github.com/python/cpython/issues/91308
>
> Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
> ---
>  lib/bb/cooker.py | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
> index 6da9291f..e417d0e1 100644
> --- a/lib/bb/cooker.py
> +++ b/lib/bb/cooker.py
> @@ -13,7 +13,10 @@ import sys, os, glob, os.path, re, time
>  import itertools
>  import logging
>  import multiprocessing
> -import sre_constants
> +if sys.version_info >= (3, 11):
> +    import re._constants as sre_constants
> +else:
> +    import sre_constants
>  import threading
>  from io import StringIO, UnsupportedOperation
>  from contextlib import closing
> --
> 2.35.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#13739): https://lists.openembedded.org/g/bitbake-devel/message/13739
> Mute This Topic: https://lists.openembedded.org/mt/91619426/1686489
> Group Owner: bitbake-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [alex.kanavin@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Richard Purdie June 8, 2022, 4:51 p.m. UTC | #2
On Wed, 2022-06-08 at 10:57 +0200, Martin Jansa wrote:
> * fixes:
>   bitbake/lib/bb/cooker.py:16: DeprecationWarning: module 'sre_constants' is deprecated
>   import sre_constants
> 
>   it's deprecated since 3.11 with:
>   https://github.com/python/cpython/issues/91308
> 
> Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
> ---
>  lib/bb/cooker.py | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
> index 6da9291f..e417d0e1 100644
> --- a/lib/bb/cooker.py
> +++ b/lib/bb/cooker.py
> @@ -13,7 +13,10 @@ import sys, os, glob, os.path, re, time
>  import itertools
>  import logging
>  import multiprocessing
> -import sre_constants
> +if sys.version_info >= (3, 11):
> +    import re._constants as sre_constants
> +else:
> +    import sre_constants
>  import threading
>  from io import StringIO, UnsupportedOperation
>  from contextlib import closing

Looking at the code we only ever use sre_constants.error and this
should really be re.error in modern python as far as I can tell so that
change may be easier ?

Cheers,

Richard

Patch

diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index 6da9291f..e417d0e1 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -13,7 +13,10 @@  import sys, os, glob, os.path, re, time
 import itertools
 import logging
 import multiprocessing
-import sre_constants
+if sys.version_info >= (3, 11):
+    import re._constants as sre_constants
+else:
+    import sre_constants
 import threading
 from io import StringIO, UnsupportedOperation
 from contextlib import closing