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

Increase warnings stacklevel to 2, un-ignore RUFF B028 #4217

Merged
merged 13 commits into from
Dec 11, 2024

Conversation

DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Dec 6, 2024

Summary

  • Increase warnings stacklevel to 2, to point to the caller instead of warnings.warn
  • Un-ignore RUFF B028: Checks for warnings.warn calls without an explicit stacklevel keyword argument
  • Replace explicit stacklevel=1, people might have misunderstood this. It's not "default stacklevel" that is bad, but "default stacklevel as 1" that is not informative
  • Remove unnecessary explicit UserWarning as it's default:

    The category argument, if given, must be a warning category class; it defaults to UserWarning.

  • Change _MPResterLegacy from default UserWarning to FutureWarning

    "You are using the legacy MPRester. This version of the MPRester will no longer be updated. "


Example

warnings.warn(f"Non-default endpoint used: {self.preamble}")

Stacklevel 1:

UserWarning: Non-default endpoint used:xxxx
warnings.warn(f"Non-default endpoint used: {self.preamble}", stacklevel=1)

vs

Stacklevel 2:

UserWarning: Non-default endpoint used: xxxx
  mpr = _MPResterLegacy(MP_API_KEY)

@DanielYang59 DanielYang59 changed the title Increase warnings stacklevel to 2 Increase warnings stacklevel to 2, un-ignore RUFF B028 Dec 6, 2024
@DanielYang59 DanielYang59 marked this pull request as ready for review December 7, 2024 07:25
@shyuep shyuep merged commit 6abf913 into materialsproject:master Dec 11, 2024
42 of 43 checks passed
@DanielYang59 DanielYang59 deleted the mp-api-legacy branch December 11, 2024 02:30
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.

2 participants