Skip to content

Commit 5f68202

Browse files
author
José Valim
committed
Deprecate usage of @behavior in favor of @behaviour
1 parent fe2e4a1 commit 5f68202

File tree

21 files changed

+51
-44
lines changed

21 files changed

+51
-44
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* Deprecations
1717
* [Kernel] `binary_to_term/1`, `binary_to_term/2`, `term_to_binary/1` and `term_to_binary/2` are deprecated in favor of their counterparts in the `:erlang` module
1818
* [Kernel] `//` for default arguments is deprecated in favor of `\\`. This is a soft deprecation, no warnings will be emitted for it in this release
19+
* [Kernel] Deprecate `@behavior` in favor of `@behaviour`
1920
* [Record] Deprecate `to_keywords`, `getter` and `list getter` functionalities in `defrecordp`
2021

2122
* Backwards incompatible changes
@@ -45,7 +46,7 @@
4546

4647
* Deprecations
4748
* [Enum] Deprecate `Enum.first/1` in favor of `Enum.at/2` and `List.first/1`
48-
* [Kernel] Deprecate continuable heredocs. In previous versions, Elixir would continue parsing on the same line the heredoc started, this behavior has been deprecated
49+
* [Kernel] Deprecate continuable heredocs. In previous versions, Elixir would continue parsing on the same line the heredoc started, this behaviour has been deprecated
4950
* [Kernel] `is_alive/0` is deprecated in favor of `Node.alive?`
5051
* [Kernel] `Kernel.inspect/2` with `Inspect.Opts[]` is deprecated in favor of `Inspect.Algebra.to_doc/2`
5152
* [Kernel] `Kernel.inspect/2` with `:raw` option is deprecated, use `:records` option instead
@@ -745,7 +746,7 @@
745746
* Backwards incompatible changes
746747
* [Kernel] Compile files now follow `Elixir-ModuleName` convention to solve issues with Erlang embedded mode. This removes the `__MAIN__` pseudo-variable as modules are now located inside `Elixir` namespace
747748
* [Kernel] `__using__` callback triggered by `use` now receives just one argument. Caller information can be accessed via macros using `__CALLER__`
748-
* [Kernel] Comprehensions syntax changed to be more compatible with Erlang behavior
749+
* [Kernel] Comprehensions syntax changed to be more compatible with Erlang behaviour
749750
* [Kernel] loop and recur are removed in favor of recursion with named functions
750751
* [Module] Removed data functions in favor of unifying the attributes API
751752

lib/eex/lib/eex/smart_engine.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule EEx.TransformerEngine do
22
@moduledoc """
33
An abstract engine that is meant to be used and
44
built upon in other modules. This engine implements
5-
the `EEx.Engine` behavior and provides a `transform`
5+
the `EEx.Engine` behaviour and provides a `transform`
66
overridable directive that allows a developer to
77
customize the expression returned by the engine.
88
@@ -13,7 +13,7 @@ defmodule EEx.TransformerEngine do
1313
@doc false
1414
defmacro __using__(_) do
1515
quote do
16-
@behavior EEx.Engine
16+
@behaviour EEx.Engine
1717

1818
def handle_text(buffer, text) do
1919
EEx.Engine.handle_text(buffer, text)

lib/elixir/lib/application/behaviour.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ defmodule Application.Behaviour do
9292
@doc false
9393
defmacro __using__(_) do
9494
quote location: :keep do
95-
@behavior :application
95+
@behaviour :application
9696

9797
@doc false
9898
def stop(_state) do

lib/elixir/lib/code.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule Code do
1010
Utilities for managing code compilation, code evaluation and code loading.
1111
1212
This module complements [Erlang's code module](http://www.erlang.org/doc/man/code.html)
13-
to add behavior which is specific to Elixir.
13+
to add behaviour which is specific to Elixir.
1414
"""
1515

1616
@doc """

lib/elixir/lib/gen_fsm/behaviour.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ defmodule GenFSM.Behaviour do
166166
@doc false
167167
defmacro __using__(_) do
168168
quote location: :keep do
169-
@behavior :gen_fsm
169+
@behaviour :gen_fsm
170170

171171
@doc false
172172
def handle_event(event, state_name, state_data) do

lib/elixir/lib/gen_server/behaviour.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ defmodule GenServer.Behaviour do
8686
@doc false
8787
defmacro __using__(_) do
8888
quote location: :keep do
89-
@behavior :gen_server
89+
@behaviour :gen_server
9090

9191
@doc false
9292
def init(args) do

lib/elixir/lib/kernel.ex

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,13 @@ defmodule Kernel do
238238

239239
@doc false
240240
def binary_to_term(binary) do
241-
IO.write "binary_to_term/1 is deprecated, please use :erlang.binary_to_term/1 instead\n#{Exception.format_stacktrace}"
241+
IO.write :stderr, "binary_to_term/1 is deprecated, please use :erlang.binary_to_term/1 instead\n#{Exception.format_stacktrace}"
242242
:erlang.binary_to_term(binary)
243243
end
244244

245245
@doc false
246246
def binary_to_term(binary, options) do
247-
IO.write "binary_to_term/2 is deprecated, please use :erlang.binary_to_term/2 instead\n#{Exception.format_stacktrace}"
247+
IO.write :stderr, "binary_to_term/2 is deprecated, please use :erlang.binary_to_term/2 instead\n#{Exception.format_stacktrace}"
248248
:erlang.binary_to_term(binary, options)
249249
end
250250

@@ -1037,13 +1037,13 @@ defmodule Kernel do
10371037

10381038
@doc false
10391039
def term_to_binary(term) do
1040-
IO.write "term_to_binary/1 is deprecated, please use :erlang.term_to_binary/1 instead\n#{Exception.format_stacktrace}"
1040+
IO.write :stderr, "term_to_binary/1 is deprecated, please use :erlang.term_to_binary/1 instead\n#{Exception.format_stacktrace}"
10411041
:erlang.term_to_binary(term)
10421042
end
10431043

10441044
@doc false
10451045
def term_to_binary(term, opts) do
1046-
IO.write "term_to_binary/2 is deprecated, please use :erlang.term_to_binary/2 instead\n#{Exception.format_stacktrace}"
1046+
IO.write :stderr, "term_to_binary/2 is deprecated, please use :erlang.term_to_binary/2 instead\n#{Exception.format_stacktrace}"
10471047
:erlang.term_to_binary(term, opts)
10481048
end
10491049

@@ -1991,10 +1991,10 @@ defmodule Kernel do
19911991
This macro is a shortcut to read and add attributes to the module
19921992
being compiled. Elixir module attributes are similar to Erlang's with
19931993
some differences. The canonical example for attributes is annotating
1994-
that a module implements the OTP behavior called `gen_server`:
1994+
that a module implements the OTP behaviour called `gen_server`:
19951995
19961996
defmodule MyServer do
1997-
@behavior :gen_server
1997+
@behaviour :gen_server
19981998
# ... callbacks ...
19991999
end
20002000
@@ -2056,22 +2056,22 @@ defmodule Kernel do
20562056
end
20572057

20582058
# @attribute value
2059-
defp do_at([arg], name, function?, _env) do
2059+
defp do_at([arg], name, function?, env) do
20602060
case function? do
20612061
true ->
20622062
raise ArgumentError, message: "cannot dynamically set attribute @#{name} inside function"
20632063
false ->
2064+
if name == :behavior do
2065+
IO.write :stderr, "warning: @behavior attribute is not supported, please use @behaviour instead\n" <>
2066+
Exception.format_stacktrace(env_stacktrace(env))
2067+
end
20642068
quote do: Module.put_attribute(__MODULE__, unquote(name), unquote(arg))
20652069
end
20662070
end
20672071

20682072
# @attribute or @attribute()
20692073
defp do_at(args, name, function?, env) when is_atom(args) or args == [] do
2070-
stack =
2071-
case bootstraped?(Path) do
2072-
true -> env.stacktrace
2073-
false -> []
2074-
end
2074+
stack = env_stacktrace(env)
20752075

20762076
case function? do
20772077
true ->
@@ -3833,6 +3833,13 @@ defmodule Kernel do
38333833
defp env_context(env), do: :erlang.element(6, env)
38343834
defp env_vars(env), do: :erlang.element(13, env)
38353835

3836+
defp env_stacktrace(env) do
3837+
case bootstraped?(Path) do
3838+
true -> env.stacktrace
3839+
false -> []
3840+
end
3841+
end
3842+
38363843
defp expand_compact([{ :compact, false }|t]), do: expand_compact(t)
38373844
defp expand_compact([{ :compact, true }|t]), do: [:compact|expand_compact(t)]
38383845
defp expand_compact([h|t]), do: [h|expand_compact(t)]

lib/elixir/lib/kernel/record_rewriter.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ defmodule Kernel.RecordRewriter do
7272
case record_fields(module, record) do
7373
{ fields, optimizable } ->
7474
opt_call =
75-
if :lists.member({ function, length(args) + 1 }, optimizable) do
75+
if { function, length(args) + 1 } in optimizable do
7676
case record_field_info(function) do
7777
{ kind, field } ->
7878
if index = Enum.find_index(fields, &(field == &1)) do

lib/elixir/lib/kernel/special_forms.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ defmodule Kernel.SpecialForms do
331331
Elixir won't emit any warnings though, since the alias
332332
was not explicitly defined.
333333
334-
Both warning behaviors could be changed by explicitily
334+
Both warning behaviours could be changed by explicitily
335335
setting the `:warn` option to true or false.
336336
"""
337337
defmacro alias(module, opts)
@@ -443,7 +443,7 @@ defmodule Kernel.SpecialForms do
443443
Elixir won't emit any warnings though, since the import
444444
was not explicitly defined.
445445
446-
Both warning behaviors could be changed by explicitily
446+
Both warning behaviours could be changed by explicitily
447447
setting the `:warn` option to true or false.
448448
449449
## Ambiguous function/macro names

lib/elixir/lib/macro.ex

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,9 @@ defmodule Macro do
182182
@doc %S"""
183183
Unescape the given chars.
184184
185-
This is the unescaping behavior
186-
used by default in Elixir single- and double-quoted strings.
187-
Check `unescape_string/2` for information on how to customize
188-
the escaping map.
185+
This is the unescaping behaviour used by default in Elixir
186+
single- and double-quoted strings. Check `unescape_string/2`
187+
for information on how to customize the escaping map.
189188
190189
In this setup, Elixir will escape the following: `\a`, `\b`,
191190
`\d`, `\e`, `\f`, `\n`, `\r`, `\s`, `\t` and `\v`. Octals are

0 commit comments

Comments
 (0)