Skip to content

Use Base.only when appropriate #2751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/Bridges/Constraint/bridges/VectorizeBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@
if x === nothing
return nothing
end
@assert length(x) == 1
return x[1] + bridge.set_constant
return only(x) + bridge.set_constant

Check warning on line 126 in src/Bridges/Constraint/bridges/VectorizeBridge.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/VectorizeBridge.jl#L126

Added line #L126 was not covered by tests
end

function MOI.get(
Expand All @@ -133,16 +132,15 @@
bridge::VectorizeBridge,
)
x = MOI.get(model, attr, bridge.vector_constraint)
@assert length(x) == 1
if MOI.Utilities.is_ray(MOI.get(model, MOI.PrimalStatus(attr.result_index)))
# If it is an infeasibility certificate, it is a ray and satisfies the
# homogenized problem, see https://github.com/jump-dev/MathOptInterface.jl/issues/433
return x[1]
return only(x)

Check warning on line 138 in src/Bridges/Constraint/bridges/VectorizeBridge.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/VectorizeBridge.jl#L138

Added line #L138 was not covered by tests
else
# Otherwise, we need to add the set constant since the ConstraintPrimal
# is defined as the value of the function and the set_constant was
# removed from the original function
return x[1] + bridge.set_constant
return only(x) + bridge.set_constant

Check warning on line 143 in src/Bridges/Constraint/bridges/VectorizeBridge.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/VectorizeBridge.jl#L143

Added line #L143 was not covered by tests
end
end

Expand Down Expand Up @@ -180,8 +178,7 @@
if x === nothing
return nothing
end
@assert length(x) == 1
return x[1]
return only(x)

Check warning on line 181 in src/Bridges/Constraint/bridges/VectorizeBridge.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/VectorizeBridge.jl#L181

Added line #L181 was not covered by tests
end

function MOI.set(
Expand Down Expand Up @@ -235,8 +232,7 @@
MOI.get(model, attr, bridge.vector_constraint),
true,
)
@assert length(f) == 1
return convert(G, f[1])
return convert(G, only(f))

Check warning on line 235 in src/Bridges/Constraint/bridges/VectorizeBridge.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/VectorizeBridge.jl#L235

Added line #L235 was not covered by tests
end

function MOI.get(
Expand Down
7 changes: 2 additions & 5 deletions src/Bridges/Variable/bridges/VectorizeBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@
bridge::VectorizeBridge,
)
x = MOI.get(model, attr, bridge.vector_constraint)
@assert length(x) == 1
y = x[1]
y = only(x)

Check warning on line 144 in src/Bridges/Variable/bridges/VectorizeBridge.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/bridges/VectorizeBridge.jl#L144

Added line #L144 was not covered by tests
status = MOI.get(model, MOI.PrimalStatus(attr.result_index))
if !MOI.Utilities.is_ray(status)
# If it is an infeasibility certificate, it is a ray and satisfies the
Expand All @@ -160,9 +159,7 @@
attr::MOI.ConstraintDual,
bridge::VectorizeBridge,
)
x = MOI.get(model, attr, bridge.vector_constraint)
@assert length(x) == 1
return x[1]
return only(MOI.get(model, attr, bridge.vector_constraint))

Check warning on line 162 in src/Bridges/Variable/bridges/VectorizeBridge.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/bridges/VectorizeBridge.jl#L162

Added line #L162 was not covered by tests
end

function MOI.get(
Expand Down
3 changes: 1 addition & 2 deletions src/FileFormats/MPS/MPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1199,8 +1199,7 @@ function Base.read!(io::IO, model::Model)
if header == HEADER_NAME
parse_name_line(data, line)
elseif header == HEADER_OBJSENSE
@assert length(items) == 1
sense = uppercase(items[1])
sense = uppercase(only(items))
@assert sense == "MAX" || sense == "MIN"
data.is_minimization = sense == "MIN"
elseif header == HEADER_ROWS
Expand Down
Loading