Skip to content

Commit 0267ae2

Browse files
lackacjosevalim
authored andcommitted
Support adding arbitrary docs metadata with @doc keyword() (#7852)
1 parent ec0435b commit 0267ae2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+351
-218
lines changed

lib/elixir/lib/access.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ defmodule Access do
774774
** (RuntimeError) Access.filter/1 expected a list, got: %{}
775775
776776
"""
777-
@since "1.6.0"
777+
@doc since: "1.6.0"
778778
@spec filter((term -> boolean)) :: access_fun(data :: list, get_value :: list)
779779
def filter(func) when is_function(func) do
780780
fn op, data, next -> filter(op, data, func, next) end

lib/elixir/lib/agent.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ defmodule Agent do
144144
145145
See `Supervisor`.
146146
"""
147-
@since "1.5.0"
147+
@doc since: "1.5.0"
148148
def child_spec(arg) do
149149
%{
150150
id: Agent,

lib/elixir/lib/calendar.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ defmodule Calendar do
234234
between them. If they are compatible, this means that we can also convert
235235
dates as well as naive datetimes between them.
236236
"""
237-
@since "1.5.0"
237+
@doc since: "1.5.0"
238238
@spec compatible_calendars?(Calendar.calendar(), Calendar.calendar()) :: boolean
239239
def compatible_calendars?(calendar, calendar), do: true
240240

@@ -247,7 +247,7 @@ defmodule Calendar do
247247
Returns a microsecond tuple truncated to a given precision (`:microsecond`,
248248
`:millisecond` or `:second`).
249249
"""
250-
@since "1.6.0"
250+
@doc since: "1.6.0"
251251
@spec truncate(Calendar.microsecond(), :microsecond | :millisecond | :second) ::
252252
Calendar.microsecond()
253253
def truncate(microsecond_tuple, :microsecond), do: microsecond_tuple

lib/elixir/lib/calendar/date.ex

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ defmodule Date do
8787
-366
8888
8989
"""
90-
91-
@since "1.5.0"
90+
@doc since: "1.5.0"
9291
@spec range(Date.t(), Date.t()) :: Date.Range.t()
9392
def range(%Date{calendar: calendar} = first, %Date{calendar: calendar} = last) do
9493
{first_days, _} = to_iso_days(first)
@@ -116,7 +115,7 @@ defmodule Date do
116115
true
117116
118117
"""
119-
@since "1.4.0"
118+
@doc since: "1.4.0"
120119
@spec utc_today(Calendar.calendar()) :: t
121120
def utc_today(calendar \\ Calendar.ISO)
122121

@@ -148,7 +147,7 @@ defmodule Date do
148147
true
149148
150149
"""
151-
@since "1.4.0"
150+
@doc since: "1.4.0"
152151
@spec leap_year?(Calendar.date()) :: boolean()
153152
def leap_year?(date)
154153

@@ -169,7 +168,7 @@ defmodule Date do
169168
29
170169
171170
"""
172-
@since "1.4.0"
171+
@doc since: "1.4.0"
173172
@spec days_in_month(Calendar.date()) :: Calendar.day()
174173
def days_in_month(date)
175174

@@ -186,7 +185,7 @@ defmodule Date do
186185
12
187186
188187
"""
189-
@since "1.7.0"
188+
@doc since: "1.7.0"
190189
@spec months_in_year(Calendar.date()) :: Calendar.month()
191190
def months_in_year(date)
192191

@@ -436,7 +435,7 @@ defmodule Date do
436435
:eq
437436
438437
"""
439-
@since "1.4.0"
438+
@doc since: "1.4.0"
440439
@spec compare(Calendar.date(), Calendar.date()) :: :lt | :eq | :gt
441440
def compare(%{calendar: calendar} = date1, %{calendar: calendar} = date2) do
442441
%{year: year1, month: month1, day: day1} = date1
@@ -484,7 +483,7 @@ defmodule Date do
484483
{:ok, %Date{calendar: Calendar.Holocene, year: 12000, month: 1, day: 1}}
485484
486485
"""
487-
@since "1.5.0"
486+
@doc since: "1.5.0"
488487
@spec convert(Calendar.date(), Calendar.calendar()) ::
489488
{:ok, t} | {:error, :incompatible_calendars}
490489
def convert(%{calendar: calendar, year: year, month: month, day: day}, calendar) do
@@ -518,7 +517,7 @@ defmodule Date do
518517
%Date{calendar: Calendar.Holocene, year: 12000, month: 1, day: 1}
519518
520519
"""
521-
@since "1.5.0"
520+
@doc since: "1.5.0"
522521
@spec convert!(Calendar.date(), Calendar.calendar()) :: t
523522
def convert!(date, calendar) do
524523
case convert(date, calendar) do
@@ -550,7 +549,7 @@ defmodule Date do
550549
~D[-0011-12-30]
551550
552551
"""
553-
@since "1.5.0"
552+
@doc since: "1.5.0"
554553
@spec add(Calendar.date(), integer()) :: t
555554
def add(%{calendar: calendar} = date, days) do
556555
{iso_days, fraction} = to_iso_days(date)
@@ -576,7 +575,7 @@ defmodule Date do
576575
-2
577576
578577
"""
579-
@since "1.5.0"
578+
@doc since: "1.5.0"
580579
@spec diff(Calendar.date(), Calendar.date()) :: integer
581580
def diff(%{calendar: Calendar.ISO} = date1, %{calendar: Calendar.ISO} = date2) do
582581
%{year: year1, month: month1, day: day1} = date1
@@ -634,7 +633,7 @@ defmodule Date do
634633
3
635634
636635
"""
637-
@since "1.4.0"
636+
@doc since: "1.4.0"
638637
@spec day_of_week(Calendar.date()) :: non_neg_integer()
639638
def day_of_week(date)
640639

lib/elixir/lib/calendar/datetime.ex

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ defmodule DateTime do
186186
#DateTime<2016-05-24 13:26:08.003Z>
187187
188188
"""
189-
@since "1.4.0"
189+
@doc since: "1.4.0"
190190
@spec from_naive(NaiveDateTime.t(), Calendar.time_zone()) :: {:ok, t}
191191
def from_naive(naive_datetime, time_zone)
192192

@@ -232,7 +232,7 @@ defmodule DateTime do
232232
#DateTime<2016-05-24 13:26:08.003Z>
233233
234234
"""
235-
@since "1.4.0"
235+
@doc since: "1.4.0"
236236
@spec from_naive!(NaiveDateTime.t(), Calendar.time_zone()) :: t
237237
def from_naive!(naive_datetime, time_zone) do
238238
case from_naive(naive_datetime, time_zone) do
@@ -502,7 +502,7 @@ defmodule DateTime do
502502
{:error, :invalid_format}
503503
504504
"""
505-
@since "1.4.0"
505+
@doc since: "1.4.0"
506506
@spec from_iso8601(String.t(), Calendar.calendar()) ::
507507
{:ok, t, Calendar.utc_offset()} | {:error, atom}
508508
def from_iso8601(string, calendar \\ Calendar.ISO) when is_binary(string) do
@@ -634,7 +634,7 @@ defmodule DateTime do
634634
:gt
635635
636636
"""
637-
@since "1.4.0"
637+
@doc since: "1.4.0"
638638
@spec compare(Calendar.datetime(), Calendar.datetime()) :: :lt | :eq | :gt
639639
def compare(
640640
%{calendar: _, utc_offset: utc_offset1, std_offset: std_offset1} = datetime1,
@@ -685,7 +685,7 @@ defmodule DateTime do
685685
-18000
686686
687687
"""
688-
@since "1.5.0"
688+
@doc since: "1.5.0"
689689
@spec diff(Calendar.datetime(), Calendar.datetime()) :: integer()
690690
def diff(
691691
%{utc_offset: utc_offset1, std_offset: std_offset1} = datetime1,
@@ -725,7 +725,7 @@ defmodule DateTime do
725725
#DateTime<2017-11-07 11:45:18+01:00 CET Europe/Paris>
726726
727727
"""
728-
@since "1.6.0"
728+
@doc since: "1.6.0"
729729
@spec truncate(t(), :microsecond | :millisecond | :second) :: t()
730730
def truncate(%DateTime{microsecond: microsecond} = datetime, precision) do
731731
%{datetime | microsecond: Calendar.truncate(microsecond, precision)}
@@ -754,7 +754,7 @@ defmodule DateTime do
754754
zone_abbr: "AMT"}}
755755
756756
"""
757-
@since "1.5.0"
757+
@doc since: "1.5.0"
758758
@spec convert(Calendar.datetime(), Calendar.calendar()) ::
759759
{:ok, t} | {:error, :incompatible_calendars}
760760

@@ -829,7 +829,7 @@ defmodule DateTime do
829829
zone_abbr: "AMT"}
830830
831831
"""
832-
@since "1.5.0"
832+
@doc since: "1.5.0"
833833
@spec convert!(Calendar.datetime(), Calendar.calendar()) :: t | no_return
834834
def convert!(datetime, calendar) do
835835
case convert(datetime, calendar) do

lib/elixir/lib/calendar/iso.ex

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ defmodule Calendar.ISO do
5151
{-365, {0, 86400000000}}
5252
5353
"""
54+
@doc since: "1.5.0"
5455
@impl true
55-
@since "1.5.0"
5656
@spec naive_datetime_to_iso_days(
5757
Calendar.year(),
5858
Calendar.month(),
@@ -81,6 +81,7 @@ defmodule Calendar.ISO do
8181
{-1, 1, 1, 0, 0, 0, {0, 6}}
8282
8383
"""
84+
@doc since: "1.5.0"
8485
@spec naive_datetime_from_iso_days(Calendar.iso_days()) :: {
8586
Calendar.year(),
8687
Calendar.month(),
@@ -91,7 +92,6 @@ defmodule Calendar.ISO do
9192
Calendar.microsecond()
9293
}
9394
@impl true
94-
@since "1.5.0"
9595
def naive_datetime_from_iso_days({days, day_fraction}) do
9696
{year, month, day} = date_from_iso_days(days)
9797
{hour, minute, second, microsecond} = time_from_day_fraction(day_fraction)
@@ -109,8 +109,8 @@ defmodule Calendar.ISO do
109109
{45296000123, 86400000000}
110110
111111
"""
112+
@doc since: "1.5.0"
112113
@impl true
113-
@since "1.5.0"
114114
@spec time_to_day_fraction(
115115
Calendar.hour(),
116116
Calendar.minute(),
@@ -137,8 +137,8 @@ defmodule Calendar.ISO do
137137
{13, 0, 0, {0, 6}}
138138
139139
"""
140+
@doc since: "1.5.0"
140141
@impl true
141-
@since "1.5.0"
142142
@spec time_from_day_fraction(Calendar.day_fraction()) ::
143143
{Calendar.hour(), Calendar.minute(), Calendar.second(), Calendar.microsecond()}
144144
def time_from_day_fraction({parts_in_day, parts_per_day}) do
@@ -156,7 +156,7 @@ defmodule Calendar.ISO do
156156

157157
# Converts year, month, day to count of days since 0000-01-01.
158158
@doc false
159-
@since "1.5.0"
159+
@doc since: "1.5.0"
160160
def date_to_iso_days(0, 1, 1) do
161161
0
162162
end
@@ -174,7 +174,7 @@ defmodule Calendar.ISO do
174174

175175
# Converts count of days since 0000-01-01 to {year, month, day} tuple.
176176
@doc false
177-
@since "1.5.0"
177+
@doc since: "1.5.0"
178178
def date_from_iso_days(days) when days in 0..3_652_424 do
179179
{year, day_of_year} = days_to_year(days)
180180
extra_day = if leap_year?(year), do: 1, else: 0
@@ -243,8 +243,8 @@ defmodule Calendar.ISO do
243243
12
244244
245245
"""
246+
@doc since: "1.7.0"
246247
@impl true
247-
@since "1.7.0"
248248
@spec months_in_year(year) :: 12
249249
def months_in_year(_year) do
250250
@months_in_year
@@ -462,8 +462,8 @@ defmodule Calendar.ISO do
462462
false
463463
464464
"""
465+
@doc since: "1.5.0"
465466
@impl true
466-
@since "1.5.0"
467467
@spec valid_date?(year, month, day) :: boolean
468468
def valid_date?(year, month, day) do
469469
month in 1..12 and year in -9999..9999 and day in 1..days_in_month(year, month)
@@ -484,8 +484,8 @@ defmodule Calendar.ISO do
484484
false
485485
486486
"""
487+
@doc since: "1.5.0"
487488
@impl true
488-
@since "1.5.0"
489489
@spec valid_time?(Calendar.hour(), Calendar.minute(), Calendar.secon(), Calendar.microsecond()) ::
490490
boolean
491491
def valid_time?(hour, minute, second, {microsecond, precision}) do
@@ -496,8 +496,8 @@ defmodule Calendar.ISO do
496496
@doc """
497497
See `c:Calendar.day_rollover_relative_to_midlight_utc/0` for documentation.
498498
"""
499+
@doc since: "1.5.0"
499500
@impl true
500-
@since "1.5.0"
501501
@spec day_rollover_relative_to_midnight_utc() :: {0, 1}
502502
def day_rollover_relative_to_midnight_utc() do
503503
{0, 1}
@@ -566,7 +566,7 @@ defmodule Calendar.ISO do
566566
do: precision_for_unit(div(number, 10), precision + 1)
567567

568568
@doc false
569-
@since "1.5.0"
569+
@doc since: "1.5.0"
570570
def date_to_iso8601(year, month, day, format \\ :extended) do
571571
date_to_string(year, month, day, format)
572572
end
@@ -671,15 +671,15 @@ defmodule Calendar.ISO do
671671
end
672672

673673
@doc false
674-
@since "1.5.0"
674+
@doc since: "1.5.0"
675675
def iso_days_to_unit({days, {parts, ppd}}, unit) do
676676
day_microseconds = days * @parts_per_day
677677
microseconds = div(parts * @parts_per_day, ppd)
678678
System.convert_time_unit(day_microseconds + microseconds, :microsecond, unit)
679679
end
680680

681681
@doc false
682-
@since "1.5.0"
682+
@doc since: "1.5.0"
683683
def add_day_fraction_to_iso_days({days, {parts, ppd}}, add, ppd) do
684684
normalize_iso_days(days, parts + add, ppd)
685685
end

0 commit comments

Comments
 (0)