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

remove lazy importer, fix circular imports #1640

merged 2 commits into from Sep 14, 2019


Copy link

fixes #2

Given that everything is so circular, importing anything basically resulted in importing everything anyway, so there wasn't really a point to the lazy importer.

Moved some imports into the functions that need them in order to break circular imports. Only http and datastructures import from each other at the bottom of the modules now, as they both do about the same amount of importing, so making one lazy didn't make sense.

Verified this by doing["python", "-c", "import {name}"]) for every module in Werkzeug. None resulted in import errors.

@davidism davidism added this to the 1.0.0 milestone Sep 12, 2019
Copy link
Member Author

davidism commented Sep 14, 2019

Based on discussion in #2, I'm deprecating most of these top-level attributes in favor of direct imports. The docs have said to use direct imports for a long time, and the top-level attributes were somewhat scattershot, it wasn't clear why certain things weren't there, or why it was useful to have certain things there. Moving the deprecated attributes back into a lazy module prevents IDEs like PyCharm from preferring werkzeug.url_quote over from werkzeug.urls import url_quote.

I left Request, Response, Client, and run_simple, as these are the things I considered most relevant to someone who just wanted to import werkzeug to do something quickly. Everything else will show a DeprecationWarning when accessed.

The werkzeug.exceptions and werkzeug.routing modules were also imported top-level, and I'm considering these deprecated as well. However, to my surprise, there is no way to distinguish between import werkzeug; werkzeug.exceptions and from werkzeug import exceptions. from tries attribute access before trying to import. I tried playing around with frame inspection, but due to the differences between Python 2, Python 3, PyPy, and the interactive interpreter, I couldn't find a reliable heuristic that wouldn't cause incorrect warnings sometimes. So these are mentioned in the changelog as deprecated, but won't show a warning.

@davidism davidism merged commit f7374b6 into master Sep 14, 2019
@davidism davidism deleted the remove-import-magic branch September 14, 2019 19:43
Copy link
Member Author

After a bit more discussion, we're going to target the deprecation at a new 0.16 release, then remove the imports altogether for 1.0. There won't be much time between the two releases, but it will offer a slightly smoother upgrade path and will mean there won't be a bunch of deprecations hanging around in 1.0

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet

Successfully merging this pull request may close these issues.

Remove Magical Import System
2 participants