Skip to content

Too strict behavior with --ignore-missing-imports #5226

Closed

Description

@ilevkivskyi

I think the --ignore-missing-imports currently behaves a bit inconsistently. If I have an existing directory with only an empty __init__.py, then running mypy with --ignore-missing-imports gives this:

import whatever.works
import existing.nonexisting

x = whatever.works.f()  # No errors, as expected
y = existing.nonexisting.g()  # Module has no attribute "nonexisting"

At the same time both these work (in the same program, otherwise the second fails):

from whatever import works  # no errors
from existing import nonexisting # no errors

I think the first example should work as well, since all non-existing modules should be replaced with a dummy Any (and apparently it looks easy to fix, unless this is intentional behavior for some reasons).

EDIT: see #5226 (comment)

Activity

  1. gvanrossum commented on Jun 17, 2018

    @gvanrossum
    Member
  2. ilevkivskyi commented on Jun 17, 2018

    @ilevkivskyi
    MemberAuthor

    Isn't this the reason we don't like partial packages in typeshed?

    Maybe. But what is the value of that error "Module has no attribute ..."?

  3. ilevkivskyi commented on Jun 17, 2018

    @ilevkivskyi
    MemberAuthor

    Correction: from existing import nonexisting also fails. It however doesn't fail, if there is an import existing.nonexisting elsewhere.

  4. gvanrossum commented on Jun 18, 2018

    @gvanrossum
    Member

    For me the deciding difference is whether it could reference something other than a module. import existing.nonexisting has to refer to a module, so --ignore-missing-imports applies. But from existing import nonexisting could refer to a class, function or variable defined in existing and as such it is not covered by --ignore-missing-imports. The presence of import existing.nonexisting elsewhere implies that it refers to a submodule, so then the flag applies.

    So I don't necessarily believe that "fixing" this will make things better -- it will just trade false positives for false negatives.

  5. ilevkivskyi commented on Jun 18, 2018

    @ilevkivskyi
    MemberAuthor

    So I don't necessarily believe that "fixing" this will make things better -- it will just trade false positives for false negatives.

    So do you prefer false positives? I prefer false negatives. Also as Jukka mentioned in the PR some users may be surprised that refactoring import a.b into from a import b turns it into an error.

  6. gvanrossum commented on Jun 18, 2018

    @gvanrossum
    Member
  7. changed the title [-]Inconsistency in --ignore-missing-imports[/-] [+]Too strict behavior with --ignore-missing-imports[/+] on Jun 18, 2018
  8. ilevkivskyi commented on Jun 18, 2018

    @ilevkivskyi
    MemberAuthor

    OK, I updated the title.

  9. added a commit that references this issue on Jun 21, 2018
    4026cb8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions