Skip to content

Commit c803e10

Browse files
musmararslan
authored andcommitted
Add isnothing (#654)
1 parent f7bdd76 commit c803e10

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ Currently, the `@compat` macro supports the following syntaxes:
120120

121121
## New functions, macros, and methods
122122

123+
* `isnothing` for testing if a variable is equal to `nothing` ([#29674]).
124+
123125
* `Compat.readline` with `keep` keyword argument ([#25646])
124126

125127
* `Compat.eachline` with `keep` keyword argument ([#25646])
@@ -573,3 +575,4 @@ includes this fix. Find the minimum version from there.
573575
[#28708]: https://github.com/JuliaLang/julia/issues/28708
574576
[#28850]: https://github.com/JuliaLang/julia/issues/28850
575577
[#29259]: https://github.com/JuliaLang/julia/issues/29259
578+
[#29674]: https://github.com/JuliaLang/julia/issues/29674

src/Compat.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,14 @@ end
924924
export Nothing, Cvoid
925925
end
926926

927+
# https://github.com/JuliaLang/julia/pull/29679
928+
if VERSION < v"1.1.0-DEV.472"
929+
export isnothing
930+
isnothing(::Any) = false
931+
isnothing(::Nothing) = true
932+
end
933+
934+
927935
@static if !isdefined(Base, :Some)
928936
import Base: promote_rule, convert
929937
struct Some{T}

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ let s = "Koala test: 🐨"
2626
end
2727
end
2828

29+
# julia#29679
30+
@test !isnothing(1)
31+
@test isnothing(nothing)
32+
2933
# julia#26365
3034
@test Compat.tr([1 2; 3 5]) == 6
3135

0 commit comments

Comments
 (0)