Skip to content

Commit 126a5a6

Browse files
author
José Valim
committed
Deprecate more functionality to be changed or removed in v0.13
1 parent 293711f commit 126a5a6

File tree

7 files changed

+40
-123
lines changed

7 files changed

+40
-123
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
* [Mix] Automatically recompile on outdated Elixir version and show proper error messages
77

88
* Deprecations
9+
* [File] `File.stream_to!/3` is deprecated
910
* [Kernel] `%` for sigils is deprecated in favor of `~`
1011
* [Kernel] `is_range/1` and `is_regex/1` are deprecated in favor of `Range.range?/1` and `Regex.regex?/1`
12+
* [Stream] `Stream.after/1` is deprecated
13+
* [URI] `URI.decode_query/1` is deprecated in favor of `URI.decode_query/2` with explicit dict argument
14+
* [URI] Passing lists as key or values in `URI.encode_query/1` is deprecated
1115

1216
* Backwards incompatible changes
1317

lib/elixir/lib/file.ex

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -969,20 +969,9 @@ defmodule File do
969969
Stream.resource(start_fun, next_fun, &F.close/1)
970970
end
971971

972-
@doc """
973-
Receives a stream and returns a new stream that will open the file
974-
at the given `path` for write with the extra `modes` and write
975-
each value to the file.
976-
977-
The returned stream will fail for the same reasons as
978-
`File.open!/2`. Note that the file is opened only and every time
979-
streaming begins.
980-
981-
Note that stream by default uses `IO.binwrite/2` unless
982-
the file is opened with an encoding, then the slower `IO.write/2`
983-
is used to do the proper data conversion and guarantees.
984-
"""
972+
@doc false
985973
def stream_to!(stream, path, modes \\ []) do
974+
IO.write :stderr, "File.stream_to!/3 is deprecated and will be removed/1\n#{Exception.format_stacktrace}"
986975
modes = open_defaults([:write|List.delete(modes, :write)], true)
987976
bin = nil? List.keyfind(modes, :encoding, 0)
988977

lib/elixir/lib/stream.ex

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -173,25 +173,17 @@ defmodule Stream do
173173

174174
## Transformers
175175

176-
@doc """
177-
Executes the given function when the stream is done, halted
178-
or an error happened during streaming. Useful for resource
179-
clean up.
180-
181-
Callbacks registered later will be executed earlier.
182-
183-
## Examples
184-
185-
iex> stream = Stream.after [1,2,3], fn -> Process.put(:done, true) end
186-
iex> Enum.to_list(stream)
187-
[1,2,3]
188-
iex> Process.get(:done)
189-
true
190-
191-
"""
176+
@doc false
192177
@spec unquote(:after)(Enumerable.t, (() -> term)) :: Enumerable.t
193-
def unquote(:after)(Lazy[after: funs] = lazy, fun), do: lazy.after([fun|funs])
194-
def unquote(:after)(enum, fun), do: Lazy[enum: enum, after: [fun]]
178+
def unquote(:after)(Lazy[after: funs] = lazy, fun) do
179+
IO.write :stderr, "Stream.after/1 is deprecated and will be removed/1\n#{Exception.format_stacktrace}"
180+
lazy.after([fun|funs])
181+
end
182+
183+
def unquote(:after)(enum, fun) do
184+
IO.write :stderr, "Stream.after/1 is deprecated and will be removed/1\n#{Exception.format_stacktrace}"
185+
Lazy[enum: enum, after: [fun]]
186+
end
195187

196188
@doc """
197189
Shortcut to `chunk(enum, n, n)`.
@@ -447,18 +439,6 @@ defmodule Stream do
447439
448440
This is useful when a stream needs to be run, for side effects,
449441
and there is no interest in its return result.
450-
451-
## Examples
452-
453-
Open up a file, replace all `#` by `%` and stream to another file
454-
without loading the whole file in memory:
455-
456-
stream = File.stream!("code")
457-
|> Stream.map(&String.replace(&1, "#", "%"))
458-
|> File.stream_to!("new")
459-
460-
No computation will be done until we call one of the Enum functions
461-
or `Stream.run/1`.
462442
"""
463443
@spec run(Enumerable.t) :: :ok
464444
def run(stream) do

lib/elixir/lib/uri.ex

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,14 @@ defmodule URI do
7575
"""
7676
def encode_query(l), do: Enum.map_join(l, "&", &pair/1)
7777

78+
@doc false
79+
def decode_query(q) do
80+
IO.write :stderr, "URI.decode_query/1 is deprecated, please use URI.decode_query/2 with an explicit argument\n#{Exception.format_stacktrace}"
81+
decode_query(q, HashDict.new)
82+
end
83+
7884
@doc """
79-
Decodes a query string into a `HashDict`.
85+
Decodes a query string into a dictionary.
8086
8187
Given a query string of the form "key1=value1&key2=value2...", produces a
8288
`HashDict` with one entry for each key-value pair. Each key and value will be a
@@ -86,17 +92,14 @@ defmodule URI do
8692
8793
## Examples
8894
89-
iex> URI.decode_query("foo=1&bar=2") |> Dict.to_list
90-
[{"bar", "2"}, {"foo", "1"}]
91-
9295
iex> hd = HashDict.new()
9396
iex> URI.decode_query("foo=1&bar=2", hd) |> HashDict.keys
9497
["bar", "foo"]
9598
iex> URI.decode_query("foo=1&bar=2", hd) |> HashDict.values
9699
["2", "1"]
97100
98101
"""
99-
def decode_query(q, dict \\ HashDict.new) when is_binary(q) do
102+
def decode_query(q, dict) when is_binary(q) do
100103
Enum.reduce query_decoder(q), dict, fn({ k, v }, acc) -> Dict.put(acc, k, v) end
101104
end
102105

@@ -134,6 +137,16 @@ defmodule URI do
134137
{ current, next }
135138
end
136139

140+
defp pair({k, v}) when is_list(k) do
141+
IO.write :stderr, "Passing list keys to URI.encode_query/1 is deprecated\n#{Exception.format_stacktrace}"
142+
encode(to_string(k)) <> "=" <> encode(to_string(v))
143+
end
144+
145+
defp pair({k, v}) when is_list(v) do
146+
IO.write :stderr, "Passing list values to URI.encode_query/1 is deprecated\n#{Exception.format_stacktrace}"
147+
encode(to_string(k)) <> "=" <> encode(to_string(v))
148+
end
149+
137150
defp pair({k, v}) do
138151
encode(to_string(k)) <> "=" <> encode(to_string(v))
139152
end

lib/elixir/test/elixir/file_test.exs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -966,23 +966,6 @@ defmodule FileTest do
966966
end
967967
end
968968

969-
test :stream_to do
970-
src = fixture_path("file.txt")
971-
dest = tmp_path("tmp_test.txt")
972-
973-
try do
974-
stream = File.stream!(src)
975-
|> Stream.map(&String.replace(&1, "O", "A"))
976-
|> File.stream_to!(dest)
977-
978-
refute File.exists?(dest)
979-
assert Stream.run(stream) == :ok
980-
assert File.read(dest) == { :ok, "FAA\n" }
981-
after
982-
File.rm(dest)
983-
end
984-
end
985-
986969
test :stream_bytes do
987970
src = fixture_path("file.txt")
988971
dest = tmp_path("tmp_test.txt")

lib/elixir/test/elixir/stream_test.exs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,6 @@ defmodule StreamTest do
2525
assert Enum.to_list(stream) == [3,5,7]
2626
end
2727

28-
test "after" do
29-
stream = Stream.after([1,2,3], fn -> Process.put(:stream_after, true) end)
30-
31-
# Done
32-
Process.put(:stream_after, false)
33-
assert Enum.to_list(stream) == [1,2,3]
34-
assert Process.get(:stream_after)
35-
36-
# Halted
37-
Process.put(:stream_after, false)
38-
assert Enum.take(stream, 1) == [1]
39-
assert Process.get(:stream_after)
40-
end
41-
42-
test "after closes on errors" do
43-
stream = Stream.after([1,2,3], fn -> Process.put(:stream_after, true) end)
44-
45-
Process.put(:stream_after, false)
46-
stream = Stream.map(stream, fn x -> if x > 2, do: throw(:error), else: x end)
47-
assert catch_throw(Enum.to_list(stream)) == :error
48-
assert Process.get(:stream_after)
49-
end
50-
5128
test "chunk" do
5229
assert Stream.chunk([1, 2, 3, 4, 5], 2) |> Enum.to_list ==
5330
[[1, 2], [3, 4]]
@@ -464,17 +441,14 @@ defmodule StreamTest do
464441

465442
test "run" do
466443
Process.put(:stream_each, [])
467-
Process.put(:stream_after, false)
468444

469445
stream = [1,2,3]
470-
|> Stream.after(fn -> Process.put(:stream_after, true) end)
471446
|> Stream.each(fn x ->
472447
Process.put(:stream_each, [x|Process.get(:stream_each)])
473448
end)
474449

475450
assert is_lazy(stream)
476451
assert Stream.run(stream) == :ok
477-
assert Process.get(:stream_after)
478452
assert Process.get(:stream_each) == [3,2,1]
479453
end
480454

@@ -532,25 +506,6 @@ defmodule StreamTest do
532506
assert Process.get(:stream_zip) == :done
533507
end
534508

535-
test "zip/2 closes on inner error" do
536-
stream = Stream.after([1, 2, 3], fn -> Process.put(:stream_zip, true) end)
537-
stream = Stream.zip(stream, Stream.map([:a, :b, :c], fn _ -> throw(:error) end))
538-
539-
Process.put(:stream_zip, false)
540-
assert catch_throw(Enum.to_list(stream)) == :error
541-
assert Process.get(:stream_zip)
542-
end
543-
544-
test "zip/2 closes on outer error" do
545-
stream = Stream.after([1, 2, 3], fn -> Process.put(:stream_zip, true) end)
546-
|> Stream.zip([:a, :b, :c])
547-
|> Stream.map(fn _ -> throw(:error) end)
548-
549-
Process.put(:stream_zip, false)
550-
assert catch_throw(Enum.to_list(stream)) == :error
551-
assert Process.get(:stream_zip)
552-
end
553-
554509
test "with_index" do
555510
stream = Stream.with_index([1,2,3])
556511
assert is_lazy(stream)

lib/elixir/test/elixir/uri_test.exs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,20 @@ defmodule URITest do
1212
test :encode_query do
1313
assert URI.encode_query([{:foo, :bar}, {:baz, :quux}]) == "foo=bar&baz=quux"
1414
assert URI.encode_query([{"foo", "bar"}, {"baz", "quux"}]) == "foo=bar&baz=quux"
15-
assert URI.encode_query([{'foo', 'bar'}, {'baz', 'quux'}]) == "foo=bar&baz=quux"
16-
end
17-
18-
test :encode_query_mixed do
1915
assert URI.encode_query([{"foo", :bar}]) == "foo=bar"
20-
assert URI.encode_query([{"foo", 'bar'}]) == "foo=bar"
21-
assert URI.encode_query([{:foo, "bar"}]) == "foo=bar"
22-
assert URI.encode_query([{:foo, 'bar'}]) == "foo=bar"
2316
end
2417

2518
test :decode_query do
26-
assert HashDict.equal?(URI.decode_query("q=search%20query&cookie=ab%26cd&block%20buster="),
19+
assert HashDict.equal?(URI.decode_query("q=search%20query&cookie=ab%26cd&block%20buster=", HashDict.new),
2720
HashDict.new [{"block buster", ""}, {"cookie", "ab&cd"}, {"q", "search query"}])
28-
assert HashDict.equal?(URI.decode_query(""), HashDict.new)
29-
assert HashDict.equal?(URI.decode_query("something=weird%3Dhappening"), HashDict.new [{"something", "weird=happening"}])
21+
assert HashDict.equal?(URI.decode_query("", HashDict.new), HashDict.new)
22+
assert HashDict.equal?(URI.decode_query("something=weird%3Dhappening", HashDict.new), HashDict.new [{"something", "weird=happening"}])
3023

3124
assert URI.decode_query("", []) == []
3225

33-
assert HashDict.equal?(URI.decode_query("garbage"), HashDict.new [{"garbage", nil}])
34-
assert HashDict.equal?(URI.decode_query("=value"), HashDict.new [{"", "value"}])
35-
assert HashDict.equal?(URI.decode_query("something=weird=happening"), HashDict.new [{"something", "weird=happening"}])
26+
assert HashDict.equal?(URI.decode_query("garbage", HashDict.new), HashDict.new [{"garbage", nil}])
27+
assert HashDict.equal?(URI.decode_query("=value", HashDict.new), HashDict.new [{"", "value"}])
28+
assert HashDict.equal?(URI.decode_query("something=weird=happening", HashDict.new), HashDict.new [{"something", "weird=happening"}])
3629
end
3730

3831
test :decoder do

0 commit comments

Comments
 (0)