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
merged 2 commits into from Sep 14, 2019

Conversation

@davidism
Copy link
Member

commented Sep 12, 2019

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 subprocess.run(["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
@jab
jab approved these changes Sep 13, 2019
@davidism

This comment has been minimized.

Copy link
Member Author

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
11 checks passed
11 checks passed
Tests Build #20190914.1 had test failures
Details
Tests (Job Docs) Job Docs succeeded
Details
Tests (Job PyPy 3 Linux) Job PyPy 3 Linux succeeded
Details
Tests (Job Python 2.7 Linux) Job Python 2.7 Linux succeeded
Details
Tests (Job Python 2.7 Windows) Job Python 2.7 Windows succeeded
Details
Tests (Job Python 3.5 Linux) Job Python 3.5 Linux succeeded
Details
Tests (Job Python 3.6 Linux) Job Python 3.6 Linux succeeded
Details
Tests (Job Python 3.7 Linux) Job Python 3.7 Linux succeeded
Details
Tests (Job Python 3.7 Mac) Job Python 3.7 Mac succeeded
Details
Tests (Job Python 3.7 Windows) Job Python 3.7 Windows succeeded
Details
Tests (Job Style) Job Style succeeded
Details
@davidism davidism deleted the remove-import-magic branch Sep 14, 2019
@davidism

This comment has been minimized.

Copy link
Member Author

commented Sep 15, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.