diff options
author | Matt Davis <mrd@redhat.com> | 2021-01-20 13:15:18 -0800 |
---|---|---|
committer | Ingy döt Net <ingy@ingy.net> | 2021-01-20 16:39:29 -0500 |
commit | 2b37f155d4313ea352f8576d84dda3025b8edf9c (patch) | |
tree | 8c7e4dd923cfd4e362ec8863cd22a417fc6879c6 | |
parent | 58d0cb7ee09954c67fabfbd714c5673b03e7a9e1 (diff) | |
download | pyyaml-git-2b37f155d4313ea352f8576d84dda3025b8edf9c.tar.gz |
Fix stub compat with older pyyaml versions that may unwittingly load it
-rw-r--r-- | lib/_yaml/__init__.py | 4 | ||||
-rw-r--r-- | lib3/_yaml/__init__.py | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/lib/_yaml/__init__.py b/lib/_yaml/__init__.py index 2dadafc..7baa8c4 100644 --- a/lib/_yaml/__init__.py +++ b/lib/_yaml/__init__.py @@ -5,7 +5,9 @@ # close enough for anyone who's relying on it even when they shouldn't. import yaml -if not yaml.__with_libyaml__: +# in some circumstances, the yaml module we imoprted may be from a different version, so we need +# to tread carefully when poking at it here (it may not have the attributes we expect) +if not getattr(yaml, '__with_libyaml__', False): from sys import version_info exc = ModuleNotFoundError if version_info >= (3, 6) else ImportError diff --git a/lib3/_yaml/__init__.py b/lib3/_yaml/__init__.py index 2dadafc..7baa8c4 100644 --- a/lib3/_yaml/__init__.py +++ b/lib3/_yaml/__init__.py @@ -5,7 +5,9 @@ # close enough for anyone who's relying on it even when they shouldn't. import yaml -if not yaml.__with_libyaml__: +# in some circumstances, the yaml module we imoprted may be from a different version, so we need +# to tread carefully when poking at it here (it may not have the attributes we expect) +if not getattr(yaml, '__with_libyaml__', False): from sys import version_info exc = ModuleNotFoundError if version_info >= (3, 6) else ImportError |