From 2b37f155d4313ea352f8576d84dda3025b8edf9c Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Wed, 20 Jan 2021 13:15:18 -0800 Subject: 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 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 -- cgit v1.2.1