-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
bpo-5664: 2to3 convert Cookie.Cookie properly #15268
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
Changes from all commits
f227b39
ad3c21d
f994c2b
67be373
3f72fa0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -276,6 +276,13 @@ and off individually. They are described here in more detail. | |||
| Handles other modules renames in the standard library. It is separate from | ||||
| the :2to3fixer:`imports` fixer only because of technical limitations. | ||||
|
|
||||
| .. 2to3fixer:: imports3 | ||||
|
|
||||
| Handles other modules renames in the standard library. It is separate from | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| the :2to3fixer:`imports` and :2to3fixer:`imports2` fixers only because of | ||||
| technical limitations. :2to3fixer:`renames` needs to run afterwards to | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are these technical limitations?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test_imports() would fail, because this fix uses 2 steps. fix_renames does a second change after fix_imports. |
||||
| rename :data:`http.cookies.Cookie` to :data:`http.cookies.SimpleCookie`. | ||||
|
|
||||
| .. 2to3fixer:: input | ||||
|
|
||||
| Converts ``input(prompt)`` to ``eval(input(prompt))``. | ||||
|
|
@@ -389,7 +396,8 @@ and off individually. They are described here in more detail. | |||
|
|
||||
| .. 2to3fixer:: renames | ||||
|
|
||||
| Changes :data:`sys.maxint` to :data:`sys.maxsize`. | ||||
| Changes :data:`sys.maxint` to :data:`sys.maxsize` and | ||||
| :data:`http.cookies.Cookie` to :data:`http.cookies.SimpleCookie`. | ||||
|
|
||||
| .. 2to3fixer:: repr | ||||
|
|
||||
|
|
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -44,7 +44,7 @@ | |||
| 'httplib': 'http.client', | ||||
| 'htmlentitydefs' : 'html.entities', | ||||
| 'HTMLParser' : 'html.parser', | ||||
| 'Cookie': 'http.cookies', | ||||
| #'Cookie': 'http.cookies', is handled by fix_imports3 + renames | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can remove this line. |
||||
| 'cookielib': 'http.cookiejar', | ||||
| 'BaseHTTPServer': 'http.server', | ||||
| 'SimpleHTTPServer': 'http.server', | ||||
|
|
@@ -139,7 +139,10 @@ def transform(self, node, results): | |||
| self.transform(node, results) | ||||
| else: | ||||
| # Replace usage of the module. | ||||
| bare_name = results["bare_with_attr"][0] | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this change do? (when is results["bare_with_attr"] not a list?)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When there is only 1 key/value in MAPPING like in fix_imports3. |
||||
| if isinstance(results["bare_with_attr"],list): | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| bare_name = results["bare_with_attr"][0] | ||||
| else: | ||||
| bare_name = results["bare_with_attr"] | ||||
| new_name = self.replace.get(bare_name.value) | ||||
| if new_name: | ||||
| bare_name.replace(Name(new_name, prefix=bare_name.prefix)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| """Fix incompatible imports and module references that get fix_renames after | ||
| fix_imports. | ||
| """ | ||
| from . import fix_imports | ||
|
|
||
|
|
||
| MAPPING = { | ||
| 'Cookie': 'http.cookies', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you format indentation in this file? |
||
| } | ||
|
|
||
|
|
||
| class FixImports3(fix_imports.FixImports): | ||
|
|
||
| run_order = 7 | ||
|
|
||
| mapping = MAPPING |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1815,6 +1815,23 @@ class Test_imports2(FixerTestCase, ImportsFixerTests): | |
| from ..fixes.fix_imports2 import MAPPING as modules | ||
|
|
||
|
|
||
| class Test_imports3(FixerTestCase): | ||
|
|
||
| def setUp(self): | ||
| super(Test_imports3, self).setUp(['imports3', 'renames']) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you only include |
||
|
|
||
| def test_cookie(self): | ||
| b = """ | ||
| import Cookie | ||
| c = Cookie.Cookie('abc') | ||
| """ | ||
| a = """ | ||
| import http.cookies | ||
| c = http.cookies.SimpleCookie('abc') | ||
| """ | ||
| self.check(b, a) | ||
|
|
||
|
|
||
| class Test_imports_fixer_order(FixerTestCase, ImportsFixerTests): | ||
|
|
||
| def setUp(self): | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 2to3 convert Cookie.Cookie properly. Patch by Aldwin Pollefeyt |
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.