python3: use __spec__.cached when looking for cached bytecode
PATCH 1/1 python3: use __spec__.cached when looking for cached bytecode
The __cached__ attribute has been deprecated since Python 3.13 and has been removed in 3.15:
The __cached__ attribute on modules, which was deprecated since version 3.13, is no longer set or taken into consideration by the import system or standard library. Use __spec__.cached instead.[1]
Replace __cached__ with __spec__.cached, and remove obsolete exception handling that doesn't get triggered with the current standard library.
[1] https://docs.python.org/3/whatsnew/3.15.html
Signed-off-by Ross Burton <[email protected]>
--- .../python/python3/get_module_deps3.py | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-)
meta/recipes-devtools/python/python3/get_module_deps3.py +3 -18
@@ -143,24 +143,9 @@ for item in dif: cpython_tag = sys.implementation.cache_tag cached = '' - # Theres no naive way to find *.pyc files on python3 - try: - if debug == True: - log.write('\nCalling: sys.modules[' + '%s' % item + '].__cached__\n') - cached = sys.modules['%s' % item].__cached__ - except AttributeError as e: - # Deals with thread (builtin module) not having __cached__ attribute - if debug == True: - log.write(item + ' ') - log.write(str(e)) - log.write('\n') - pass - except NameError as e: - # Deals with NameError: name 'cached' is not defined - if debug == True: - log.write(item+' ') - log.write(str(e)) - pass + if debug == True: + log.write('\nGetting cached attribute for %s\n' % item) + cached = sys.modules['%s' % item].__spec__.cached if cached is not None: if debug == True: log.write(cached + '\n')
Signature · 1 line
2.43.0