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

Fix TypeError when processing relative imports #61

Merged
merged 1 commit into from May 12, 2016

Conversation

jayvdb
Copy link
Member

@jayvdb jayvdb commented May 4, 2016

Fixes lp:1560134

aec68a7 added module names to error messages,
however it caused a TypeError for relative imports
that do not specify a module such as:

from . import x

This fixes the TypeError, and also adds the necessary
leading dots for relative import error messages.

Add tests for various types of relative imports.

@jayvdb
Copy link
Member Author

jayvdb commented May 4, 2016

Note that I also have another approach that is narrower in what it fixes (i.e. not fixing the error messages for relative star imports), but it also adds a RelativeImportation which may be useful in the future.

@@ -1128,6 +1133,8 @@ def IMPORTFROM(self, node):
else:
self.futuresAllowed = False

module = ('.' * node.level) + (node.module or '')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively this could be

if node.level:
    module = ('.' * node.level) + (node.module or '')
else:
    module = node.module

@bitglue
Copy link
Member

bitglue commented May 5, 2016

If someone else could review this and give it a 👍 I'd really appreciate it. I'm pressed for time today and this is an important bugfix. I'll do the release as soon as the review is good.

@jayvdb
Copy link
Member Author

jayvdb commented May 5, 2016

It is a bit late here; I'll be up again in a few hours and can do some more testing and address any additional review comments arising.

Fixes lp:1560134

aec68a7 added module names to error messages,
however it caused a TypeError for relative imports
that do not specify a module such as:

   from . import x

This fixes the TypeError, and also adds the necessary
leading dots for relative import error messages.

Add tests for various types of relative imports.
@warsaw
Copy link

warsaw commented May 10, 2016

I don't really have an opinion on the patch, but would like to see this fixed of course. I've subscribed to this thread so once the patch lands, I can cherry pick it into the Debian/Ubuntu packages, or if a new upstream release will happen soon after, I'll be happy to upload it.

@hpk42
Copy link

hpk42 commented May 12, 2016

As Barry i also hit the problem now and would like to see it addressed. If i may, what about merging and releasing and seeing if anyone gets problems? As it currently stands 1.2 produces the traceback (i have flakes failing for 7 files in one project) where 1.1 was fine.

@warsaw
Copy link

warsaw commented May 12, 2016

Certainly, if a new upstream was released with this patch, I'd just upload it to Debian/Ubuntu and that would solve it. I'll end up doing it that way anyway for a new upstream, when we can drop this patch.

Okay, let me see about importing this patch into the Debian package instead of the previous quick hack.

@bitglue bitglue merged commit d859199 into PyCQA:master May 12, 2016
@bitglue
Copy link
Member

bitglue commented May 12, 2016

just released 1.2.3 to fix this

@sigmavirus24
Copy link
Member

We should do a 1.2.3 hotfix with the version 1.2.3.4 so we don't miss out on this opportunity ;)

@scop
Copy link
Contributor

scop commented May 13, 2016

Looks like the 1.2.3 tag is missing from the repo...

@bitglue
Copy link
Member

bitglue commented May 13, 2016

whoops, forgot to push. Fixed now, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants