Skip to content

Commit

Permalink
Remove unnecessary conversion Module <-> PkgId
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Jul 17, 2023
1 parent eebfbd1 commit 8dbb2f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
11 changes: 4 additions & 7 deletions src/piracy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end

# based on Test/Test.jl#detect_ambiguities
# https://github.com/JuliaLang/julia/blob/v1.9.1/stdlib/Test/src/Test.jl#L1838-L1896
function all_methods(mods::Module...; skip_deprecated::Bool)
function all_methods(mods::Module...; skip_deprecated::Bool = true)
meths = Method[]
mods = collect(mods)::Vector{Module}

Expand Down Expand Up @@ -173,12 +173,9 @@ function is_pirate(meth::Method; treat_as_own = Union{Function,Type}[])
)
end

hunt(mod::Module; from::Module = mod, kwargs...) =
hunt(Base.PkgId(mod); from = from, kwargs...)

function hunt(pkg::Base.PkgId; from::Module, skip_deprecated::Bool = true, kwargs...)
filter(all_methods(from; skip_deprecated = skip_deprecated)) do method
Base.PkgId(method.module) === pkg && is_pirate(method; kwargs...)
function hunt(mod::Module; skip_deprecated::Bool = true, kwargs...)
filter(all_methods(mod; skip_deprecated = skip_deprecated)) do method
method.module === mod && is_pirate(method; kwargs...)
end
end

Expand Down
11 changes: 5 additions & 6 deletions test/test_piracy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ using Aqua: Piracy
using PiracyForeignProject: ForeignType, ForeignParameterizedType, ForeignNonSingletonType

# Get all methods - test length
meths = filter(Piracy.all_methods(PiracyModule; skip_deprecated = true)) do m
meths = filter(Piracy.all_methods(PiracyModule)) do m
m.module == PiracyModule
end

Expand All @@ -90,7 +90,7 @@ ThisPkg = Base.PkgId(PiracyModule)
@test !Piracy.is_foreign(Set{Int}, CorePkg; treat_as_own = [])

# Test what is pirate
pirates = filter(m -> Piracy.is_pirate(m), meths)
pirates = Piracy.hunt(PiracyModule)
@test length(pirates) ==
3 + # findfirst
3 + # findmax
Expand All @@ -102,7 +102,7 @@ pirates = filter(m -> Piracy.is_pirate(m), meths)
end

# Test what is pirate (with treat_as_own=[ForeignType])
pirates = filter(m -> Piracy.is_pirate(m; treat_as_own = [ForeignType]), meths)
pirates = Piracy.hunt(PiracyModule, treat_as_own = [ForeignType])
@test length(pirates) ==
3 + # findfirst
3 + # findmin
Expand All @@ -112,7 +112,7 @@ pirates = filter(m -> Piracy.is_pirate(m; treat_as_own = [ForeignType]), meths)
end

# Test what is pirate (with treat_as_own=[ForeignParameterizedType])
pirates = filter(m -> Piracy.is_pirate(m; treat_as_own = [ForeignParameterizedType]), meths)
pirates = Piracy.hunt(PiracyModule, treat_as_own = [ForeignParameterizedType])
@test length(pirates) ==
3 + # findfirst
3 + # findmax
Expand All @@ -135,8 +135,7 @@ pirates = filter(
end

# Test what is pirate (with treat_as_own=[Base.findfirst, Base.findmax])
pirates =
filter(m -> Piracy.is_pirate(m; treat_as_own = [Base.findfirst, Base.findmax]), meths)
pirates = Piracy.hunt(PiracyModule, treat_as_own = [Base.findfirst, Base.findmax])
@test length(pirates) ==
3 + # findmin
1 + # ForeignType callable
Expand Down

0 comments on commit 8dbb2f5

Please sign in to comment.