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

add spaces between type parameters and Dict entries #37085

Merged
merged 1 commit into from
Aug 29, 2020
Merged

Conversation

JeffBezanson
Copy link
Sponsor Member

I expect this to be my most dramatic PR ever. I think this situation has gotten a bit silly:

julia> Tuple{typeof(isequal), Union{Nothing, Float64}, Union{Nothing, Float64}}
Tuple{typeof(isequal),Union{Nothing, Float64},Union{Nothing, Float64}}

julia> :(Tuple{Int,Int})
:(Tuple{Int, Int})

julia> Tuple{Int,Int}
Tuple{Int64,Int64}

Now that the Vector and Matrix (etc.) type printing change is done, many of the tests this would break are already fixed. I'll fix the remainder if there is agreement.

@JeffBezanson JeffBezanson added domain:display and printing Aesthetics and correctness of printed representations of objects. kind:minor change Marginal behavior change acceptable for a minor release labels Aug 17, 2020
@JeffBezanson JeffBezanson added status:triage This should be discussed on a triage call and removed status:triage This should be discussed on a triage call labels Aug 27, 2020
@JeffBezanson JeffBezanson added the status:merge me PR is reviewed. Merge when all tests are passing label Aug 28, 2020
@JeffBezanson JeffBezanson changed the title add spaces between type parameters add spaces between type parameters and Dict entries Aug 29, 2020
@JeffBezanson JeffBezanson merged commit 2fc3dcd into master Aug 29, 2020
@JeffBezanson JeffBezanson deleted the jb/spaces branch August 29, 2020 22:59
@fredrikekre
Copy link
Member

fredrikekre commented Aug 30, 2020

RIP every doctest in the ecosystem 😄

If people are running doctests on more than one Julia version, the following doctestfilters (https://juliadocs.github.io/Documenter.jl/stable/man/doctests/#Filtering-Doctests) can be applied to make it pass:

doctestfilters = [
    r"{([a-zA-Z0-9]+,\s?)+[a-zA-Z0-9]+}",
    r"(Array{[a-zA-Z0-9]+,\s?1}|Vector{[a-zA-Z0-9]+})",
    r"(Array{[a-zA-Z0-9]+,\s?2}|Matrix{[a-zA-Z0-9]+})",
]

which should deal with this and also the two most common failures from #36107 (Array{X,1} -> Vector{X} and Array{X,2} -> Matrix{X}).

@fredrikekre
Copy link
Member

fredrikekre commented Aug 30, 2020

Also interesting to note that in the codebase itself it seems that no space is winning:

$ grep --include \*.jl --include \*.md -roP '{([a-zA-Z0-9]+,\s)+[a-zA-Z0-9]+}' . | wc -l
2263

$ grep --include \*.jl --include \*.md -roP '{([a-zA-Z0-9]+,)+[a-zA-Z0-9]+}' . | wc -l
5101

Edit: And same in packages on my disk, no space is more common:

$ grep --include \*.jl --include \*.md -roP '{([a-zA-Z0-9]+,)+[a-zA-Z0-9]+}' . | wc -l                            
67555                                                                     

$ grep --include \*.jl --include \*.md -roP '{([a-zA-Z0-9]+,\s)+[a-zA-Z0-9]+}' . | wc -l                          
23244

@KristofferC
Copy link
Sponsor Member

Crazy idea, but maybe Documenter should apply those filters by default..?

@fredrikekre
Copy link
Member

Since doctests are pretty sensitive to printing like this, new random numbers streams etc, I think most packages only build and doctests on a single Julia version though.

@JeffBezanson
Copy link
Sponsor Member Author

Edit: And same in packages on my disk, no space is more common:

So? Should we go the other way and remove all the spaces? Or do we currently have an ideal compromise, using spaces half the time? 😄

@fredrikekre
Copy link
Member

So?

I just wanted to point out that most Julia programmers prefer no space in type parameters. That is also the recommended style according to e.g. YASGuide (https://github.com/jrevels/YASGuide#linealignmentspacing-guidelines).

Should we go the other way and remove all the spaces?

Yes: #25826 😄

@JeffBezanson
Copy link
Sponsor Member Author

Use a single space after commas and semicolons. The exception is within type parameter lists, where no spaces should be added after commas.

Seems odd to me. I would almost guess it says that just to follow how we were printing them. @jrevels is that the case?

@jrevels
Copy link
Member

jrevels commented Aug 30, 2020

I would almost guess it says that just to follow how we were printing them. @jrevels is that the case?

Originally the YASGuide did not include the type parameter list exception in its "spaces-after-commas mandate", but we added it after it was brought up that most code in the wild does not include spaces after commas in type parameter lists (jrevels/YASGuide#3). So this exception was introduced purely to follow existing "convention" (or at least our perception of it, which probably was indeed influenced by the existing printing style).

@timholy
Copy link
Sponsor Member

timholy commented Aug 30, 2020

Even if we like it better, I'm not sure that changing away from no spaces is worth it. In the JuliaImages organization we had a half-dozen PRs like this one; that was a change that seems unambiguously better, yet despite that one can't help feeling like it was sort of a waste of a couple of hours (across the multiple packages). It's not always completely trivial to write these in a way that works across multiple Julia versions with different printing conventions and yet doesn't abandon all sense that you're actually testing the output in some meaningful way. I'm not saying it's hard, but it is the kind of annoyance that we should think twice before inflicting on folks.

@mateuszbaran
Copy link
Contributor

If you are adding spaces after commas, maybe show_typealias also should have them? On the current master I have:

julia> SVector{2}
SVector{2,T} where T = SArray{Tuple{2}, T, 1, 2} where T

which is still inconsistent.

@JeffBezanson
Copy link
Sponsor Member Author

Thanks for catching that, will fix.

goretkin added a commit to goretkin/ImageFiltering.jl that referenced this pull request Sep 8, 2020
JuliaLang/julia#37085 changed how type parameters
are printed, causing the following error:

```
Borders (issue JuliaImages#85): Test Failed at /home/runner/work/ImageFiltering.jl/ImageFiltering.jl/test/2d.jl:337
  Expression: imfilter(A, kern, Fill(0, (3,)))
    Expected: ArgumentError("Fill{Int64,1}(0, (3,), (3,)) lacks the proper padding sizes for an array with 2 dimensions")
      Thrown: ArgumentError("Fill{Int64, 1}(0, (3,), (3,)) lacks the proper padding sizes for an array with 2 dimensions")
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. kind:minor change Marginal behavior change acceptable for a minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants