SHA256
1
0
forked from pool/salt
salt/fixes-for-python-3.10-502.patch

93 lines
3.0 KiB
Diff
Raw Normal View History

From 5e3ff4d662321c237ddd5b2c5c83f35a84af594c Mon Sep 17 00:00:00 2001
From: Victor Zhestkov <vzhestkov@suse.com>
Date: Tue, 5 Apr 2022 12:04:46 +0300
Subject: [PATCH] Fixes for Python 3.10 (#502)
* Fix _compat.py importlib logic for Python 3.10
Use the same logic in _compat.py and entrypoints.py to load
the same importlib.metadata. Python's built in implementation for
Python >= 3.10 and the Salt one for others.
* Use collections.abc.Mapping instead collections.Mapping in state
Co-authored-by: piterpunk <piterpunk@slackware.com>
---
salt/_compat.py | 29 +++++++++++++++++------------
salt/state.py | 4 ++--
2 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/salt/_compat.py b/salt/_compat.py
index ed404e877b..a402f17a3c 100644
--- a/salt/_compat.py
+++ b/salt/_compat.py
@@ -11,18 +11,23 @@ if sys.version_info >= (3, 9, 5):
else:
import salt.ext.ipaddress as ipaddress
-# importlib_metadata before version 3.3.0 does not include the functionality we need.
-try:
- import importlib_metadata
+if sys.version_info >= (3, 10):
+ # Python 3.10 will include a fix in importlib.metadata which allows us to
+ # get the distribution of a loaded entry-point
+ import importlib.metadata # pylint: disable=no-member,no-name-in-module
+else:
+ # importlib_metadata before version 3.3.0 does not include the functionality we need.
+ try:
+ import importlib_metadata
- importlib_metadata_version = [
- int(part)
- for part in importlib_metadata.version("importlib_metadata").split(".")
- if part.isdigit()
- ]
- if tuple(importlib_metadata_version) < (3, 3, 0):
+ importlib_metadata_version = [
+ int(part)
+ for part in importlib_metadata.version("importlib_metadata").split(".")
+ if part.isdigit()
+ ]
+ if tuple(importlib_metadata_version) < (3, 3, 0):
+ # Use the vendored importlib_metadata
+ import salt.ext.importlib_metadata as importlib_metadata
+ except ImportError:
# Use the vendored importlib_metadata
import salt.ext.importlib_metadata as importlib_metadata
-except ImportError:
- # Use the vendored importlib_metadata
- import salt.ext.importlib_metadata as importlib_metadata
diff --git a/salt/state.py b/salt/state.py
index f5579fbb69..9f3792fe5f 100644
--- a/salt/state.py
+++ b/salt/state.py
@@ -12,7 +12,6 @@ The data sent to the state calls is as follows:
"""
-import collections
import copy
import datetime
import fnmatch
@@ -25,6 +24,7 @@ import site
import sys
import time
import traceback
+from collections.abc import Mapping
import salt.channel.client
import salt.fileclient
@@ -3405,7 +3405,7 @@ class State:
"""
for chunk in high:
state = high[chunk]
- if not isinstance(state, collections.Mapping):
+ if not isinstance(state, Mapping):
continue
for state_ref in state:
needs_default = True
--
2.37.3