-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Deprecate PartialFunction.apply #6005
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
Conversation
|
Maybe we can deprecate |
|
I didn't know you could deprecate something in the middle of a release cycle. |
|
I think usually not, but this might be exotic and confusing enough to make an exception. |
|
Why can't you remove it and replace it in one go? |
|
@Jasper-M I think that it's that if you val x = PartialFunction[String, Boolean] { case "bippoid" => true }will compile before and after, but have silently different semantics, which is potentially a pitfall for migration. Granted, the 2.12.x behaviour is almost certainly not wanted, but still... |
|
True, but is that still the case when you deprecate something in the beginning a new major release (2.13.0 for instance)? Cause then it's been deprecated for a whole release cycle. Then you can't say you haven't been warned. |
|
Let's deprecate |
|
👍 to that plan — as I understand it, the recommended upgrade path for users to move to a new major Scala release has always been to upgrade to the newest point release from the last version first, fix all deprecation warnings, then bump the major version |
|
Sounds good. I'll clean this up somewhere this week. |
5fcaa15 to
6562ee4
Compare
|
If we deprecate A hypothetical workaround might be to implement |
|
I don’t see why we can’t add fromFunction in 2.13 immediately. The
deprecation message can’t refer to it in 2.12, true. Then again, do we need
it at all? I don’t know, having a hard time imagining the use case
…On Thu, Nov 30, 2017 at 03:19 Jasper Moeys ***@***.***> wrote:
If we deprecate apply in 2.12.5, we can't add fromFunction at the same
time. Should the deprecation message suggest using val pf:
PartialFunction[A,B] = { case x => f(x) } instead of PartialFunction(f)?
And then add fromFunction in a separate pull request to 2.13.x?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#6005 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAFjy77KPH2dd-9d4ixffn1t8PmO_S8Jks5s7o88gaJpZM4Oive3>
.
|
Well yes, then I would need separate pull requests for both?
I'm not sure, but it's there so I guess people might be using it. The best use case I can imagine is circumventing some badly designed API. |
|
Right, you will need a 2.12 and 2.13 PR. I’m not a strong reject on
fromFunction, but maybe then those poorly designed apis should change
instead of enabling them to persevere in their wrongness? /me goes to have
coffee now
…On Thu, Nov 30, 2017 at 07:29 Jasper Moeys ***@***.***> wrote:
I don’t see why we can’t add fromFunction in 2.13 immediately. The
deprecation message can’t refer to it in 2.12, true.
Well yes, then I would need separate pull requests for both?
Then again, do we need it at all? I don’t know, having a hard time
imagining the use case
I'm not sure, but it's there so I guess people might be using it. The best
use case I can imagine is circumventing some badly designed API.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#6005 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAFjy4-QJVqZrlWJX6XYXJUP_FlkBDYzks5s7snYgaJpZM4Oive3>
.
|
|
Fine by me. I don't use it anyway 😅 |
6562ee4 to
0cddad7
Compare
PartialFunction.apply causes confusion because at first glance it looks like a general purpose factory method for creating PartialFunctions, but it is only meant to convert ordinary to partial functions (with `pf.isDefinedAt(x) == true` for all x). When used in the wrong way it can have confusing semantics.
|
FWIW I'm pretty sure I've had times where I had a function instance and something expected a PartialFunction, and .apply came in handy. |
|
Definitely, but this is about the |
|
No, on the companion. (I suppose the instance method would be the opposite case but anyway that's definitely not what I'm talking about!) |
|
I'm not sure we reached a clear conclusion on whether there ought to be a followup PR that adds related but separate question — do we want to actually remove |
|
Perhaps add |
|
If it helps, I am absolutely sure I have needed PartialFunction.fromFunction quite a bit. I am not sure if it's an edge case but I work with scalafix a fair bit which has an api that is largely based around collecting over trees, and it isn't that uncommon to find myself down a path where at a particular point I have a partial function and it wants a partial function. |
|
I was only able to find one usage, and the function being passed to it was
`identity`. So an identity partial function helper might be nice. ;)
…On Mon, Feb 26, 2018 at 9:47 PM Shane Delmore ***@***.***> wrote:
If it helps, I am absolutely sure I have needed
PartialFunction.fromFunction quite a bit. I am not sure if it's an edge
case but I work with scalafix a fair bit which has an api that is largely
based around collecting over trees, and it isn't that uncommon to find
myself down a path where at a particular point I have a partial function
and it wants a partial function.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#6005 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAGAUKzuqzi9f6H3o1IpQ_3gDYBF3iA7ks5tY2zSgaJpZM4Oive3>
.
|
|
I just want to chime in with my 2¢ that I don't like the proposal (perhaps no longer on the table) to replace this with a new If the plan is ultimately to replace the The need to cross-compile libraries in Scala exacerbates the issue as people have code that's simultaneously compiled against several versions. A compilation failure makes clear the danger here. I'm also +1 for adding a |
|
I don't see how it would be catastrophic. You would just get an error
saying found Function1..., expected PartialFunction...
Anyway, if the inheritance hierarchy were the right way, with Function1
extending PartialFunction, then this change would be moot.
…On Tue, Mar 20, 2018, 9:55 PM Sarah Gerweck ***@***.***> wrote:
I just want to chime in with my 2¢ that I don't like the proposal (perhaps
no longer on the table) to replace this with a new apply in 2.13.0. It
seems unnecessarily dangerous to deprecate something in 2.12.5 and then
replace it with a method that will accept the old source code but silently
misbehave in 2.13.0.
If the plan is ultimately to replace the apply with a source-incompatible
version, my (unsolicited) opinion would favor removing it in 2.13 rather
than leaving it with a deprecation. Yes, there would have been a
deprecation for a full version cycle, but the consequences of the behavior
change if somebody misses the deprecation warning are potentially
catastrophic. (It is clearly a good idea to enable them, but scalac
doesn't even show the actual deprecation warnings by default.)
The need to cross-compile libraries in Scala exacerbates the issue as
people have code that's simultaneously compiled against several versions. A
compilation failure makes clear the danger here.
I'm also +1 for adding a PartialFunction.fromFunction (or
Function.toPartial). When basic stuff like this is left out of the
standard library, it just winds up accumulating little helpers in a million
projects. I think there are enough use cases that it belongs
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#6005 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAGAUAMgT4-cYHstzbPB5uFzINeExw4Yks5tgbMlgaJpZM4Oive3>
.
|
|
Thanks, @sarahgerweck, and your opinion is very much solicited, and appreciated. I share the concern of silently changing behavior. We can't assume all deprecation warnings will be seen. So, to summarize proposed next steps: add @nafg, sorry for misunderstanding your earlier comment. Do you find this an acceptable compromise? PS: If we are too worried about dropping |
Sounds good to me.
You mean the person who is cross-compiling can easily add that extension himself?
The short version of |
|
Nit, but it seems to me |
|
I don't think it's redundant. Theoretically there are other things a
PartialFunction could be constructed from. Unless you mean it's redundant
with the parameter type.
You might put total in the name, since you're building a PartialFunction
that's really not partial. PartialFunction.total, or
PartialFunction.fromTotalFunction...
…On Wed, Mar 21, 2018, 7:43 AM Lukas Rytz ***@***.***> wrote:
Nit, but it seems to me PartialFunction.from is enough,
PartialFunction.fromFunction is redundant.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6005 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAGAUEKFBVJMGzf57SBP1JS38JF4wHHFks5tgjz6gaJpZM4Oive3>
.
|
Follow up of #5897.
Unfortunately
applycan't be overloaded...I suggest replacing this
applywith one that accepts aPartialFunctionas soon as possible. In my opinionlooks and feels better than
I am open to suggestions for improving the deprecation message. It doesn't cover the fact that for instance
def foo(pf: PartialFunction[Int, String]) = ???; foo{ case 1 => "one" }just works without explicit types at the use site. But I fail to put that in a short, understandable message that doesn't throw terms like "expected type" in an unsuspecting user's face. I might be overthinking this.