Implicit relative#50
Conversation
|
|
||
| def assertWarningWithFix(self, _, warning, expected_msg, expected_fix): | ||
| self.assertTrue(hasattr(warning, 'fix')) | ||
| self.assertEqual(str(warning.message) + ': ' + str(warning.fix), expected_msg + ': ' + expected_fix) |
There was a problem hiding this comment.
Rather than "..." + ".." f strings would probably be clearer?
| if (strcmp(potential_resolved, buf) == 0) { | ||
| char msg[524]; | ||
| char fix[260]; | ||
| if (is_from_form) { |
There was a problem hiding this comment.
I think we can get to this line with is_from_form uninitialised?
|
This looks mostly good, but I have a couple of small comments. |
|
@MWR27 I didn't notice the changes: if you can ping me when you need a review, that will alert me, thanks. |
|
Please squash (note: this doesn't mean you necessarily have to squash down to one commit). |
Sorry @ltratt, I've never squashed commits before. I somehow made more commits than there was before. I'll try again. |
|
Please let me know when you're done. |
|
@ltratt I'm ready for a review. I added the remaining tests for implicit relative imports and fixed an issue when catching warnings. I plan to fix the other failing test cases not related to imports in a separate pull request. |
|
I think this is ready: my suggestion (in this case) is that squashing down to one commit is probably the right thing to do. |
Python 2 supports implicit relative imports inside packages. A bare import inside a package can resolve to a sibling module.
Example package:
In Python 2, this can resolve to:
In Python 3, imports are absolute by default, so the same code resolves to:
This means that the code can import a different top-level module or fail with
ImportError.For same environment of
Python 2 resolves to
pkg.foo.Python 3 resolves to top-level
foo.I modified import.c to fire warning only if
To ensure above, it checks that the importing module has a parent package, that there are no dots in the import name, and that the resolved name is equivalent to:
parent_package + "." + imported_nameFor example, with
import foo, there are no dots infooandpkg + "." + foo == pkg.fooTherefore, the import depended on Python 2 implicit relative import behavior, so pygrate2 emits a warning.