Skip to content

Commit c274365

Browse files
committed
The yaml.load{,_all} functions require Loader= now
1 parent 2f87ac4 commit c274365

File tree

2 files changed

+5
-43
lines changed

2 files changed

+5
-43
lines changed

lib/yaml/__init__.py

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,12 @@
1818
import io
1919

2020
#------------------------------------------------------------------------------
21-
# Warnings control
21+
# XXX "Warnings control" is now deprecated. Leaving in the API function to not
22+
# break code that uses it.
2223
#------------------------------------------------------------------------------
23-
24-
# 'Global' warnings state:
25-
_warnings_enabled = {
26-
'YAMLLoadWarning': True,
27-
}
28-
29-
# Get or set global warnings' state
3024
def warnings(settings=None):
3125
if settings is None:
32-
return _warnings_enabled
33-
34-
if type(settings) is dict:
35-
for key in settings:
36-
if key in _warnings_enabled:
37-
_warnings_enabled[key] = settings[key]
38-
39-
# Warn when load() is called without Loader=...
40-
class YAMLLoadWarning(RuntimeWarning):
41-
pass
42-
43-
def load_warning(method):
44-
if _warnings_enabled['YAMLLoadWarning'] is False:
45-
return
46-
47-
import warnings
48-
49-
message = (
50-
"calling yaml.%s() without Loader=... is deprecated, as the "
51-
"default Loader is unsafe. Please read "
52-
"https://msg.pyyaml.org/load for full details."
53-
) % method
54-
55-
warnings.warn(message, YAMLLoadWarning, stacklevel=3)
26+
return {}
5627

5728
#------------------------------------------------------------------------------
5829
def scan(stream, Loader=Loader):
@@ -100,30 +71,22 @@ def compose_all(stream, Loader=Loader):
10071
finally:
10172
loader.dispose()
10273

103-
def load(stream, Loader=None):
74+
def load(stream, Loader):
10475
"""
10576
Parse the first YAML document in a stream
10677
and produce the corresponding Python object.
10778
"""
108-
if Loader is None:
109-
load_warning('load')
110-
Loader = FullLoader
111-
11279
loader = Loader(stream)
11380
try:
11481
return loader.get_single_data()
11582
finally:
11683
loader.dispose()
11784

118-
def load_all(stream, Loader=None):
85+
def load_all(stream, Loader):
11986
"""
12087
Parse all YAML documents in a stream
12188
and produce corresponding Python objects.
12289
"""
123-
if Loader is None:
124-
load_warning('load_all')
125-
Loader = FullLoader
126-
12790
loader = Loader(stream)
12891
try:
12992
while loader.check_data():

tests/lib/test_dump_load.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ def test_load_no_loader(verbose=False):
1010
except TypeError:
1111
return True
1212
assert(False, "load() require Loader=...")
13-
1413
test_load_no_loader.unittest = True
1514

1615
def test_load_safeloader(verbose=False):

0 commit comments

Comments
 (0)