Skip to content

Commit 0bc44bf

Browse files
authored
Merge pull request #2366 from ksss/json-remove-deprecated-methods
Remove deprecated methods in `JSON`
2 parents a329e54 + b98a74e commit 0bc44bf

File tree

3 files changed

+11
-167
lines changed

3 files changed

+11
-167
lines changed

stdlib/json/0/json.rbs

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ end
1414
class JSON::GeneratorError < JSON::JSONError
1515
end
1616

17-
class JSON::UnparserError < JSON::GeneratorError
18-
end
19-
2017
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
2118
# This exception is raised if a parser error occurs.
2219
#
@@ -754,13 +751,15 @@ module JSON
754751
# opts = JSON.dump_default_options
755752
# opts # => {:max_nesting=>false, :allow_nan=>true}
756753
#
754+
%a{deprecated}
757755
def self.dump_default_options: () -> options
758756

759757
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
760758
# Sets or returns the default options for the JSON.dump method. Initially:
761759
# opts = JSON.dump_default_options
762760
# opts # => {:max_nesting=>false, :allow_nan=>true}
763761
#
762+
%a{deprecated}
764763
def self.dump_default_options=: (options) -> options
765764

766765
# <!--
@@ -778,12 +777,9 @@ module JSON
778777
# # Raises SystemStackError (stack level too deep):
779778
# JSON.fast_generate(a)
780779
#
780+
%a{deprecated}
781781
def self?.fast_generate: (_ToJson obj, ?options opts) -> String
782782

783-
alias self.fast_unparse self.fast_generate
784-
785-
alias fast_unparse fast_generate
786-
787783
# <!--
788784
# rdoc-file=ext/json/lib/json/common.rb
789785
# - JSON.generate(obj, opts = nil) -> new_string
@@ -830,14 +826,6 @@ module JSON
830826

831827
def self.generator=: (generator generator) -> void
832828

833-
# <!--
834-
# rdoc-file=ext/json/lib/json/common.rb
835-
# - iconv(to, from, string)
836-
# -->
837-
# Encodes string using String.encode.
838-
#
839-
def self.iconv: (encoding to, encoding from, String string) -> String
840-
841829
# <!--
842830
# rdoc-file=ext/json/lib/json/common.rb
843831
# - JSON.load(source, proc = nil, options = {}) -> object
@@ -974,7 +962,8 @@ module JSON
974962
# #<Admin:0x00000000064c41f8
975963
# @attributes={"type"=>"Admin", "password"=>"0wn3d"}>}
976964
#
977-
def self?.load: (string | _ReadableIO | _Read source, ?Proc proc, ?options options) -> untyped
965+
def self?.load: (string | _ReadableIO | _Read source, ?options options) -> untyped
966+
| [T] (string | _ReadableIO | _Read source, ^(?) -> T, ?options options) -> T
978967

979968
# <!--
980969
# rdoc-file=ext/json/lib/json/common.rb
@@ -1003,13 +992,15 @@ module JSON
1003992
# opts = JSON.load_default_options
1004993
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
1005994
#
995+
%a{deprecated}
1006996
def self.load_default_options: () -> options
1007997

1008998
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
1009999
# Sets or returns default options for the JSON.load method. Initially:
10101000
# opts = JSON.load_default_options
10111001
# opts # => {:max_nesting=>false, :allow_nan=>true, :allow_blank=>true, :create_additions=>true}
10121002
#
1003+
%a{deprecated}
10131004
def self.load_default_options=: (options) -> options
10141005

10151006
# <!--
@@ -1120,29 +1111,6 @@ module JSON
11201111
#
11211112
def self?.pretty_generate: (_ToJson obj, ?options opts) -> untyped
11221113

1123-
alias self.pretty_unparse self.pretty_generate
1124-
1125-
alias pretty_unparse pretty_generate
1126-
1127-
# Recursively calls passed *Proc* if the parsed data structure is an *Array* or
1128-
# *Hash*
1129-
#
1130-
def self?.recurse_proc: (untyped result) { (*untyped) -> void } -> void
1131-
1132-
# <!--
1133-
# rdoc-file=ext/json/lib/json/common.rb
1134-
# - restore(source, proc = nil, options = nil)
1135-
# -->
1136-
#
1137-
alias self.restore self.load
1138-
1139-
# <!--
1140-
# rdoc-file=ext/json/lib/json/common.rb
1141-
# - restore(source, proc = nil, options = nil)
1142-
# -->
1143-
#
1144-
alias restore load
1145-
11461114
# <!-- rdoc-file=ext/json/lib/json/common.rb -->
11471115
# Sets or Returns the JSON generator state class that is used by JSON.
11481116
#
@@ -1152,10 +1120,6 @@ module JSON
11521120
# Sets or Returns the JSON generator state class that is used by JSON.
11531121
#
11541122
def self.state=: (state) -> state
1155-
1156-
alias self.unparse self.generate
1157-
1158-
alias unparse generate
11591123
end
11601124

11611125
JSON::FAST_STATE_PROTOTYPE: JSON::state
@@ -1193,6 +1157,7 @@ module Kernel
11931157
# Outputs *objs* to STDOUT as JSON strings in the shortest form, that is in one
11941158
# line.
11951159
#
1160+
%a{deprecated}
11961161
def j: (*_ToJson) -> nil
11971162

11981163
# <!--
@@ -1202,6 +1167,7 @@ module Kernel
12021167
# Outputs *objs* to STDOUT as JSON strings in a pretty format, with indentation
12031168
# and over many lines.
12041169
#
1170+
%a{deprecated}
12051171
def jj: (*_ToJson) -> nil
12061172

12071173
# <!--

test/stdlib/json/JSONKernel_test.rb

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,6 @@ class JSONKernelInstanceTest < Test::Unit::TestCase
77
library "json"
88
testing "::Kernel"
99

10-
def silent
11-
orig_stdout = $stdout
12-
$stdout = StringIO.new
13-
yield
14-
ensure
15-
$stdout = orig_stdout
16-
end
17-
18-
def test_j
19-
silent do
20-
assert_send_type("(Integer) -> nil", self, :j, 1)
21-
assert_send_type("(Array[Integer]) -> nil", self, :j, [1, 2, 3])
22-
end
23-
end
24-
25-
def test_jj
26-
silent do
27-
assert_send_type("(Integer) -> nil", self, :jj, 1)
28-
assert_send_type("(Array[Integer]) -> nil", self, :jj, [1, 2, 3])
29-
end
30-
end
31-
3210
def test_JSON
3311
assert_send_type("(String) -> Hash[String, Integer]", self, :JSON, '{"a": 1}')
3412
assert_send_type("(Array[Integer]) -> String", self, :JSON, [1, 2, 3])

test/stdlib/json/JSON_test.rb

Lines changed: 2 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,6 @@ def test_dump
6161
assert_send_type "(ToJson, JsonWrite, Integer) -> JsonWrite", JSON, :dump, ToJson.new, JsonWrite.new, 100
6262
end
6363

64-
def test_dump_default_options
65-
assert_send_type "() -> { max_nesting: false, allow_nan: true }", JSON, :dump_default_options
66-
end
67-
68-
def test_dump_default_options_eq
69-
assert_send_type "(max_nesting: false, allow_nan: true, allow_blank: true) -> { max_nesting: false, allow_nan: true, allow_blank: true }",
70-
JSON,
71-
:dump_default_options=,
72-
{ max_nesting: false, allow_nan: true, allow_blank: true }
73-
end
74-
75-
def test_fast_generate
76-
assert_send_type "(ToJson) -> String", JSON, :fast_generate, ToJson.new
77-
assert_send_type "(ToJson, indent: String) -> String", JSON, :fast_generate, ToJson.new, { indent: "\t" }
78-
end
79-
80-
def test_fast_unparse
81-
assert_send_type "(ToJson) -> String", JSON, :fast_unparse, ToJson.new
82-
assert_send_type "(ToJson, indent: String) -> String", JSON, :fast_unparse, ToJson.new, { indent: "\t" }
83-
end
84-
8564
def test_generate
8665
assert_send_type "(ToJson) -> String", JSON, :generate, ToJson.new
8766
assert_send_type "(ToJson, indent: String) -> String", JSON, :generate, ToJson.new, { indent: "\t" }
@@ -95,19 +74,13 @@ def test_generator=
9574
assert_send_type "(singleton(JSON::Ext::Generator)) -> void", JSON, :generator=, JSON::Ext::Generator
9675
end
9776

98-
def test_iconv
99-
assert_send_type "(Encoding, Encoding, String) -> String", JSON, :iconv, Encoding::UTF_8, Encoding::UTF_16, "".encode(Encoding::UTF_16)
100-
assert_send_type "(String, String, String) -> String", JSON, :iconv, 'UTF-8', 'UTF-16', "".encode(Encoding::UTF_16)
101-
assert_send_type "(_ToStr, _ToStr, String) -> String", JSON, :iconv, JsonToStr.new('UTF-8'), JsonToStr.new('UTF-16'), "".encode(Encoding::UTF_16)
102-
end
103-
10477
def test_load
10578
assert_send_type "(String) -> 42", JSON, :load, "42"
10679
assert_send_type "(_ToStr) -> 42", JSON, :load, JsonToStr.new("42")
10780
assert_send_type "(JsonToReadableIO) -> 42", JSON, :load, JsonToReadableIO.new
10881
assert_send_type "(JsonRead) -> 42", JSON, :load, JsonRead.new
109-
assert_send_type "(String, Proc) -> 42", JSON, :load, "42", proc { }
110-
assert_send_type "(String, Proc, Hash[untyped, untyped]) -> 42", JSON, :load, "42", proc { }, { alllow_nan: true }
82+
assert_send_type "(String, Proc) -> 42", JSON, :load, "42", proc { |a| a }
83+
assert_send_type "(String, Proc, Hash[untyped, untyped]) -> 42", JSON, :load, "42", proc { |a| a }, { alllow_nan: true }
11184
end
11285

11386
def test_load_file
@@ -130,14 +103,6 @@ def test_load_file!
130103
end
131104
end
132105

133-
def test_load_default_options
134-
assert_send_type "() -> Hash[untyped, untyped]", JSON, :load_default_options
135-
end
136-
137-
def test_load_default_options_eq
138-
assert_send_type "(allow_nan: true) -> Hash[untyped, untyped]", JSON, :load_default_options=, { allow_nan: true }
139-
end
140-
141106
def test_parse
142107
assert_send_type "(String) -> 42", JSON, :parse, "42"
143108
assert_send_type "(_ToStr) -> 42", JSON, :parse, JsonToStr.new("42")
@@ -163,36 +128,13 @@ def test_pretty_generate
163128
assert_send_type "(ToJson, indent: String) -> String", JSON, :pretty_generate, ToJson.new, { indent: "\t" }
164129
end
165130

166-
def test_pretty_unparse
167-
assert_send_type "(ToJson) -> String", JSON, :pretty_unparse, ToJson.new
168-
assert_send_type "(ToJson, indent: String) -> String", JSON, :pretty_unparse, ToJson.new, { indent: "\t" }
169-
end
170-
171-
def test_recurse_proc
172-
assert_send_type "(Integer) { (Integer) -> void } -> void", JSON, :recurse_proc, 42 do |_i| end
173-
end
174-
175-
def test_restore
176-
assert_send_type "(String) -> 42", JSON, :restore, "42"
177-
assert_send_type "(_ToStr) -> 42", JSON, :restore, JsonToStr.new("42")
178-
assert_send_type "(JsonToReadableIO) -> 42", JSON, :restore, JsonToReadableIO.new
179-
assert_send_type "(JsonRead) -> 42", JSON, :restore, JsonRead.new
180-
assert_send_type "(String, Proc) -> 42", JSON, :restore, "42", proc { }
181-
assert_send_type "(String, Proc, Hash[untyped, untyped]) -> 42", JSON, :restore, "42", proc { }, { alllow_nan: true }
182-
end
183-
184131
def test_state
185132
assert_send_type "() -> singleton(JSON::Ext::Generator::State)", JSON, :state
186133
end
187134

188135
def test_state_eq
189136
assert_send_type "(singleton(JSON::Ext::Generator::State)) -> singleton(JSON::Ext::Generator::State)", JSON, :state=, JSON::Ext::Generator::State
190137
end
191-
192-
def test_unparse
193-
assert_send_type "(ToJson) -> String", JSON, :unparse, ToJson.new
194-
assert_send_type "(ToJson, indent: String) -> String", JSON, :unparse, ToJson.new, { indent: "\t" }
195-
end
196138
end
197139

198140
class JSONInstanceTest < Test::Unit::TestCase
@@ -217,30 +159,11 @@ def test_dump
217159
assert_send_type "(ToJson, JsonWrite, Integer) -> JsonWrite", MyJSON.new, :dump, ToJson.new, JsonWrite.new, 100
218160
end
219161

220-
def test_fast_generate
221-
assert_send_type "(ToJson) -> String", MyJSON.new, :fast_generate, ToJson.new
222-
assert_send_type "(ToJson, indent: String) -> String", MyJSON.new, :fast_generate, ToJson.new, { indent: "\t" }
223-
end
224-
225-
def test_fast_unparse
226-
assert_send_type "(ToJson) -> String", MyJSON.new, :fast_unparse, ToJson.new
227-
assert_send_type "(ToJson, indent: String) -> String", MyJSON.new, :fast_unparse, ToJson.new, { indent: "\t" }
228-
end
229-
230162
def test_generate
231163
assert_send_type "(ToJson) -> String", MyJSON.new, :generate, ToJson.new
232164
assert_send_type "(ToJson, indent: String) -> String", MyJSON.new, :generate, ToJson.new, { indent: "\t" }
233165
end
234166

235-
def test_load
236-
assert_send_type "(String) -> 42", MyJSON.new, :load, "42"
237-
assert_send_type "(_ToStr) -> 42", MyJSON.new, :load, JsonToStr.new("42")
238-
assert_send_type "(JsonToReadableIO) -> 42", MyJSON.new, :load, JsonToReadableIO.new
239-
assert_send_type "(JsonRead) -> 42", MyJSON.new, :load, JsonRead.new
240-
assert_send_type "(String, Proc) -> 42", MyJSON.new, :load, "42", proc { }
241-
assert_send_type "(String, Proc, Hash[untyped, untyped]) -> 42", MyJSON.new, :load, "42", proc { }, { alllow_nan: true }
242-
end
243-
244167
def test_parse
245168
assert_send_type "(String) -> 42", MyJSON.new, :parse, "42"
246169
assert_send_type "(_ToStr) -> 42", MyJSON.new, :parse, JsonToStr.new("42")
@@ -258,29 +181,6 @@ def test_pretty_generate
258181
assert_send_type "(ToJson, indent: String) -> String", MyJSON.new, :pretty_generate, ToJson.new, { indent: "\t" }
259182
end
260183

261-
def test_pretty_unparse
262-
assert_send_type "(ToJson) -> String", MyJSON.new, :pretty_unparse, ToJson.new
263-
assert_send_type "(ToJson, indent: String) -> String", MyJSON.new, :pretty_unparse, ToJson.new, { indent: "\t" }
264-
end
265-
266-
def test_recurse_proc
267-
assert_send_type "(Integer) { (Integer) -> void } -> void", MyJSON.new, :recurse_proc, 42 do |_i| end
268-
end
269-
270-
def test_restore
271-
assert_send_type "(String) -> 42", MyJSON.new, :restore, "42"
272-
assert_send_type "(_ToStr) -> 42", MyJSON.new, :restore, JsonToStr.new("42")
273-
assert_send_type "(JsonToReadableIO) -> 42", MyJSON.new, :restore, JsonToReadableIO.new
274-
assert_send_type "(JsonRead) -> 42", MyJSON.new, :restore, JsonRead.new
275-
assert_send_type "(String, Proc) -> 42", MyJSON.new, :restore, "42", proc { }
276-
assert_send_type "(String, Proc, Hash[untyped, untyped]) -> 42", MyJSON.new, :restore, "42", proc { }, { alllow_nan: true }
277-
end
278-
279-
def test_unparse
280-
assert_send_type "(ToJson) -> String", MyJSON.new, :unparse, ToJson.new
281-
assert_send_type "(ToJson, indent: String) -> String", MyJSON.new, :unparse, ToJson.new, { indent: "\t" }
282-
end
283-
284184
def test_to_json_with_object
285185
assert_send_type "() -> String", Object.new, :to_json
286186
assert_send_type "(JSON::State) -> String", Object.new, :to_json, JSON::State.new

0 commit comments

Comments
 (0)