From 2acf0bc4a651fc28d22c3dad18f8b1cf0604c6f3 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Wed, 20 Jan 2021 13:15:18 -0800 Subject: [PATCH] Fix stub compat with older pyyaml versions that may unwittingly load it --- lib/_yaml/__init__.py | 4 +++- 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 2dadafc1..7baa8c4b 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 2dadafc1..7baa8c4b 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