-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 deprecation notice for Time.now #7586
Add deprecation notice for Time.now #7586
Conversation
Sigh, sometimes I wish we'd keep a few aliases. I already fathom how much time I'll lose with |
I'm not strictly opposed to make |
Please note the prior discussion about alias/deprecation in #5346 after the merge. |
I would vouch for a deprecation cycle and a --check compiler option. There is little gain with this compile time error. When possible the author of shards should be able to support two crystal versions at the same time to simplify migration paths. |
Following the discussion here and in crystal-lang/crystal-mysql#73, I've changed this PR to re-add |
Only changing the method to an alias without any deprecation warning, and probably most users who don't read carefully the changelog won't notice the deprecation, even if it appears in the API docs. |
@j8r Yes, that's what we want. For now at least. This is a breaking change, but given it's widespread use, it shouldn't immediately break every code. Let's give people time to adapt and keep support for both I'd like to keep |
19c49c2
to
7808761
Compare
@straight-shoota What we can do is leave the alias but still output a warning at compile-time. The warning is annoying but your code will work. But because it's annoying people will change the What do you think? |
We had similar discussions about compiler warnings before, but I think it was largely agreed that the compiler should either work or fail, and don't print warnings. Anyway, I'd say it's fine to merge this as is, adding a deprecation notice in the API docs. Let's see what the suggested compiler check feature brings and continue this discussion afterwards. |
Will only work after 0.28 is released. |
df50707
to
7808761
Compare
@straight-shoota we can do {% if compare_versions(Crystal::VERSION, "0.28.0-0") >= 0 %}
@[Deprecated("....")]
{% end %}
def foo
end |
Let's just add that after 0.28.0. this PR can be merged without. |
But then the deprecation will exist from 0.29. |
I don't see what's the benefit of adding a version guard for a deprecation annotation instead of simply adding the deprecation annotation after the next release? |
That it could be removed in 0.29.0. That's the only benefit I see. Since we are adding it again for 0.28 for a migration path I thought we wanted to remove it as early as possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking that we can add the annotation as a source file too in the top level, and even document it. Then we can use it right away and the next compiler will pick it up. What do you think? /cc @bcardiff
We should do the same too for other attributes (link, packed, etc)
src/time.cr
Outdated
# Creates a new `Time` instance representing the current time from the | ||
# system clock observed in *location* (defaults to local time zone). | ||
# | ||
# DEPRECATED: `Time.now` is deprecated, use `Time.local` or `Time.utc` instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are ready for a rebase and remove the deprecated comment here and in the other method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to push 🕺
23fcb53
to
ff255e8
Compare
Use Time.local instead of Time.now see crystal-lang/crystal#7586
This is a follow up on #5346 and adds the following error message for
Time.now
, guiding the user to fixing this breaking change: