Skip to content

refactor(map): deprecate op-get for future migration #2017

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

Merged
merged 1 commit into from
May 6, 2025

Conversation

peter-jerry-ye
Copy link
Collaborator

@peter-jerry-ye peter-jerry-ye commented Apr 27, 2025

In the future, we will have op_get return V instead of V? and get return V?.

For other functions, if there are a 'unsafe' implementation and a 'safe', the unsafe one will be named as unsafe_xxx. Otherwise it will just named as it is.

cc @Yoorkin the json.mbt emitted two same warnings

Related #1332

@peter-jerry-ye peter-jerry-ye requested a review from bobzhang April 27, 2025 08:06
Copy link

peter-jerry-ye-code-review bot commented Apr 27, 2025

Missing deprecation message in some interface files

Category
Correctness
Code Snippet
builtin/builtin.mbti:
#deprecated
op_get[K : Hash + Eq, V](Self[K, V], K) -> V?
Recommendation
Add consistent deprecation message across all files:
#deprecated("Use get instead. op_get will return V instead of Option[V] in the future.")
Reasoning
Some interface files (.mbti) only have #deprecated without the message. Adding consistent messages helps developers understand why the function is deprecated and what to use instead.

Change in json.mbt might need additional null checking

Category
Maintainability
Code Snippet
json/json.mbt:
Some(obj) => obj.get(key)
None => None
Recommendation
Consider whether additional handling is needed for the case where get returns None:
Some(obj) => match obj.get(key) {
Some(v) => Some(v)
None => None
}
None => None
Reasoning
The change from obj[key] to obj.get(key) might need explicit handling of the None case if get returns an optional value.

Consider adding migration guide in documentation

Category
Maintainability
Code Snippet
Multiple files: adding #deprecated attribute
Recommendation
Add a migration guide in documentation explaining:

  1. Why op_get behavior is changing
  2. Timeline for the change
  3. How to migrate existing code
    Reasoning
    Since this is a significant change in API behavior (from returning V? to V), users need clear guidance on how to update their code before the change takes effect.

@coveralls
Copy link
Collaborator

coveralls commented Apr 27, 2025

Pull Request Test Coverage Report for Build 6576

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 92.41%

Totals Coverage Status
Change from base Build 6574: 0.01%
Covered Lines: 6136
Relevant Lines: 6640

💛 - Coveralls

@bobzhang bobzhang force-pushed the zihang/deprecate-map-op-get branch from 412f765 to 551c72b Compare May 6, 2025 09:10
@bobzhang bobzhang enabled auto-merge (rebase) May 6, 2025 09:15
@bobzhang bobzhang merged commit 749bf9f into main May 6, 2025
12 checks passed
@bobzhang bobzhang deleted the zihang/deprecate-map-op-get branch May 6, 2025 09:16
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.

3 participants