Skip to content
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

Omnibus PR containing multiple improvements #24

Merged
merged 11 commits into from
Dec 11, 2020
Merged

Omnibus PR containing multiple improvements #24

merged 11 commits into from
Dec 11, 2020

Conversation

DilumAluthge
Copy link
Contributor

@DilumAluthge DilumAluthge commented Nov 5, 2020

This PR makes the following changes:

  1. Bug fix: fixes a bug in which applyfield! would never be applied to the 32nd field of a mutable struct (Bug: when calling applyfield! on a mutable struct, the 32nd field is skipped #22)
  2. New feature: adds the public makeobj and makeobj! functions
  3. New feature: adds the ability to automatically omit all empty fields in a struct
  4. New feature: adds the ability for users to override the behavior of isempty for their own structs
  5. Test suite: makes some small improvements to a few existing unit tests
  6. Test suite: Sets up GitHub Actions CI on this repository
  7. Bumps the version number in Project.toml from 1.1.0 to 1.2.0

Fixes the following issues:

Fixes quinnj/JSON3.jl#78
Fixes quinnj/JSON3.jl#90
Fixes #15
Fixes #22

Closes the following pull requests:

Closes #16
Closes #19
Closes #20
Closes #21

@codecov
Copy link

codecov bot commented Nov 5, 2020

Codecov Report

Merging #24 (fa4268c) into master (d6e2506) will increase coverage by 0.20%.
The diff coverage is 77.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #24      +/-   ##
==========================================
+ Coverage   89.24%   89.44%   +0.20%     
==========================================
  Files           1        1              
  Lines         186      218      +32     
==========================================
+ Hits          166      195      +29     
- Misses         20       23       +3     
Impacted Files Coverage Δ
src/StructTypes.jl 89.44% <77.14%> (+0.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0d1fd10...fa4268c. Read the comment docs.

@DilumAluthge DilumAluthge changed the title Omnibus PR Omnibus PR that contains multiple improvements Nov 5, 2020
@DilumAluthge DilumAluthge changed the title Omnibus PR that contains multiple improvements Omnibus PR containing multiple improvements Nov 5, 2020
@kescobo kescobo added the enhancement New feature or request label Nov 5, 2020
@kescobo kescobo requested a review from quinnj November 5, 2020 14:40
Copy link
Member

@quinnj quinnj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good overall; I prefer PRs to be much smaller, because most of this could be merged right away, but there are parts that need more discussion/iteration.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
Project.toml Outdated Show resolved Hide resolved
src/StructTypes.jl Outdated Show resolved Hide resolved
@@ -132,6 +142,8 @@ isempty(::Number) = false
isempty(::Nothing) = true
isempty(x) = false
isempty(x, i) = isempty(Core.getfield(x, i))
isempty(::Type{T}, x) where {T} = isempty(x) # generic fallback
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you walk through why this is needed? What's your use-case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows users to customize the behavior of isempty for their own structs without modifying the behavior of isempty for other types or committing any type piracy.

For example, suppose that I want missing to be treated as empty when serializing my structs. I can just do isempty(::Type{MyType}, ::Missing) = true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little more explanation is here: #21

src/StructTypes.jl Show resolved Hide resolved
@@ -686,4 +703,57 @@ mappings will be applied, and the function will be passed the Julia field name.
return f_applied
end

"""
makeobj(::Type{Any}, obj::Any)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we just call this construct; we already have that defined in StructTypes, but that's really what we're doing here, and custom types are still able to overload it if they want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, personally I'd find it confusing if this functionality was also named construct.

src/StructTypes.jl Outdated Show resolved Hide resolved
@DilumAluthge
Copy link
Contributor Author

I prefer PRs to be much smaller

I agree 100%. I almost never make PRs this big. The only reason I did so in this case is that when I tried merging the individual PRs locally, I realized that there were a lot of merge conflicts between the individual PRs.

@DilumAluthge
Copy link
Contributor Author

@quinnj This is ready for a second round of review.

@quinnj quinnj merged commit 6994754 into JuliaData:master Dec 11, 2020
@quinnj
Copy link
Member

quinnj commented Dec 11, 2020

Ok, merge this for now; but I'd like to work on the makeobj more; I'd like it to be more general and make sure we're using/respecting all the StructTypes machinery.

@DilumAluthge DilumAluthge deleted the dpa/omnibus-pr branch December 11, 2020 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants