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

allow predicate functions to lstrip etc. and default to stripping unicode whitespace #27309

Merged
merged 1 commit into from
Jun 15, 2018

Conversation

simonbyrne
Copy link
Contributor

This is similar to #27232, except that the predicate function is the second argument. It does not require any deprecations.

Fixes #27211.

[`isspace`](@ref) for precise details.

The optional `chars` argument specifies which characters to remove: it can be a single character,
vector or set of characters, or a predicate function.
Copy link
Member

Choose a reason for hiding this comment

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

The predicate function should always go first per our conventions, documented in the style guide in the manual.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

It is a "general rule" not a "must". Having the function argument second here seems much more natural to me.

Copy link
Member

Choose a reason for hiding this comment

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

guidelines

Copy link
Member

Choose a reason for hiding this comment

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

I disagree wholeheartedly; it seems very unnatural to me.

Copy link
Member

@ararslan ararslan left a comment

Choose a reason for hiding this comment

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

I don't think we should deviate from our argument order conventions for this case.

@simonbyrne simonbyrne added the status:triage This should be discussed on a triage call label May 30, 2018
@StefanKarpinski
Copy link
Sponsor Member

I agree with @ararslan here: predicate function as the first argument, character sets as the second; we can also allow a predicate as either the first or second argument as the user prefers since a string argument isn't callable.

@simonbyrne
Copy link
Contributor Author

Note that we do allow predicate function as a second argument to split/rsplit (this was not changed in #27252).

@ararslan
Copy link
Member

That should probably be fixed.

@Keno
Copy link
Member

Keno commented May 31, 2018

I'm also with @ararslan. It doesn't really bother me that the predicate and the chars are in different places in the argument list.

@mbauman mbauman changed the title allow predicate functions to lstrip etc. allow predicate functions to lstrip etc. and default to stripping unicode whitespace May 31, 2018
@JeffBezanson
Copy link
Sponsor Member

JeffBezanson commented Jun 7, 2018

I'm also OK with adding a predicate-as-first-argument version and just leaving the others.

@StefanKarpinski
Copy link
Sponsor Member

@simonbyrne, your PR, your call. Just do whatever you see fit and merge it once CI passes.

@ararslan
Copy link
Member

Can I make one last plea to put the function argument first?

@ararslan
Copy link
Member

Seems there was broad support for at least allowing that.

remove last use of _default_delims.
@simonbyrne
Copy link
Contributor Author

@ararslan I am sympathetic, and I have thought a lot about it, but my opinion is that:

  1. keeping argument order somewhat consistent is preferable to adhering to the function first rule
  2. if we really want to allow predicate function also as a first argument, we can add that later without breakage.
  3. it is too late to change the argument order altogether, but it is possible to do that via deprecation without silent breakage (since we don't allow chars to be a string).

So my call is to merge this PR.

@simonbyrne
Copy link
Contributor Author

Also, I got rid of the other uses of _default_delimiters.

@ararslan
Copy link
Member

keeping argument order somewhat consistent is preferable to adhering to the function first rule

I very adamantly disagree with this, since the argument order is then not consistent. This will be a case of "functions always come first, except for this one weird case." We had that with finalizer and that was subsequently changed.

if we really want to allow predicate function also as a first argument, we can add that later without breakage

I can submit a PR to add it once this is merged, but it really makes more sense to me to just have lstrip(f, s) and lstrip(s, c) rather than lstrip(f, s), lstrip(s, c), and lstrip(s, f). But if that's unacceptable I'll just add lstrip(f, s).

I do appreciate your work here and that you've given a lot of thought to this--I don't want you to think otherwise.

@simonbyrne simonbyrne merged commit e702275 into master Jun 15, 2018
@simonbyrne simonbyrne deleted the sb/strip2 branch June 15, 2018 22:31
@ararslan
Copy link
Member

PR to fix the argument order: #27605

@JeffBezanson
Copy link
Sponsor Member

DelimitedFiles still attempts to import _default_delims (though doesn't seem to use it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants