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
maint(fix): Add deprecation warning for accidental imports #19316
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import sympy | ||
from sympy.testing.pytest import warns_deprecated_sympy | ||
|
||
def test_deprecated_imports(): | ||
# https://github.com/sympy/sympy/pull/18245 | ||
# Before 1.6 these names were importable with e.g. | ||
# from sympy import * | ||
# from sympy import add | ||
# Now sympy/__init__.py uses __all__ so these names are no longer | ||
# accidentally imported. However many of the names now give a warning and | ||
# this test checks that they are importable but a warning is given | ||
from sympy import add | ||
|
||
with warns_deprecated_sympy(): | ||
add.Add | ||
|
||
modnames = type(add)._DEPRECATED_IMPORTS | ||
|
||
assert len(modnames) == 80 | ||
|
||
for modname in modnames: | ||
name = modname.split('.')[-1] | ||
mod = getattr(sympy, name) | ||
attr = dir(mod.mod)[0] | ||
with warns_deprecated_sympy(): | ||
getattr(mod, attr) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should subclass types.ModuleType.
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.
What difference does subclassing ModuleType make?
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.
It makes certain things that operate on modules work correctly. For example,
help()
gives special output on modules (actually that is wrong anyway, because this doesn't inherit the docstring properly).I also wonder if this could be an issue
It might or might not be an issue, I'm not sure. I guess if this turns out to cause problems, we can do a patch release that removes it.
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 think I'd prefer the help to be a message saying that you haven't imported the module in the right way (if there is any need for help at all).
The purpose of providing these deprecated module imports is just to keep code that possibly depends on importing this way chugging along but with warnings. I don't see any need to provide any other functionality.