Skip to content

[Regression: 0.470->0.501] Lots of new errors relating to "uninhabited" in Django-based app code #2978

Closed

Description

@inducer
git clone https://github.com/inducer/relate
cd relate
./run-mypy.sh

used to work with no warnings in 0.470. Now, it spews this:

course/content.py:877: error: <uninhabited> has no attribute "id"
course/content.py:1445: error: <uninhabited> has no attribute "preview_git_commit_sha"
course/content.py:1446: error: <uninhabited> has no attribute "preview_git_commit_sha"
course/utils.py:179: error: <uninhabited> has no attribute "exam"
course/utils.py:533: error: <uninhabited> has no attribute "preview_git_commit_sha"
course/utils.py:534: error: <uninhabited> has no attribute "preview_git_commit_sha"
course/utils.py:583: error: <uninhabited> has no attribute "permissions"
course/enrollment.py:129: error: <uninhabited> has no attribute "roles"
course/enrollment.py:143: error: <uninhabited> has no attribute "permissions"
course/views.py:156: error: <uninhabited> has no attribute "has_permission"
course/flow.py:416: error: <uninhabited> has no attribute "user"
course/flow.py:633: error: <uninhabited> has no attribute "answer"
course/flow.py:830: error: <uninhabited> has no attribute "get_most_recent_grade"
course/flow.py:848: error: Unsupported left operand type for + (some union)
course/flow.py:855: error: Unsupported left operand type for + (some union)
course/flow.py:862: error: Unsupported left operand type for + (some union)
course/flow.py:923: error: <uninhabited> has no attribute "is_submitted_answer"
course/flow.py:924: error: <uninhabited> has no attribute "save"
course/flow.py:1264: error: <uninhabited> has no attribute "get_most_recent_grade"

Focusing on the first error:

https://github.com/inducer/relate/blob/fed97182f4e8940bb032a224c5cbcd007a8bd722/course/content.py#L877

it should be clear that course is an instance of Course (i.e. not None).

Activity

  1. gvanrossum commented on Mar 8, 2017

    @gvanrossum
    Member

    Yeah, I can repro this. @ddfisher The script uses --strict-optional.

    I experimented with that one location a bit, and found:

    • If you replace if course is not None ... with if course ... the error goes away.
    • Without that change, reveal_type(course) inside the if shows <uninhabited>; with that change it shows Course.
    • Either way, before the if, reveal_type(course) shows Optional[Course].

    Definitely sounds like a binder issue...

  2. gvanrossum commented on Mar 8, 2017

    @gvanrossum
    Member

    @inducer If you want to help, maybe you can use git bisect to track down the exact mypy commit that caused this?

  3. inducer commented on Mar 8, 2017

    @inducer
    Author

    Would love to, but paper deadline and 12 proposals to review over the next 7 days... Sorry!

  4. refi64 commented on Mar 9, 2017

    @refi64
    Contributor

    Under mypy 0.47, I still get:

    course/flow.py:1884: error: Call to untyped function "make_form" in typed context
    course/flow.py:1943: error: Call to untyped function "form_to_html" in typed context
    course/grading.py:189: error: Call to untyped function "make_form" in typed context
    course/grading.py:206: error: Call to untyped function "form_to_html" in typed context
    course/grading.py:229: error: Call to untyped function "update_grade_data_from_grading_form_v2" in typed context
    
  5. refi64 commented on Mar 9, 2017

    @refi64
    Contributor

    Looks like some of the errors were caused by 9496d6f; I'm still trying to locate the others.

  6. refi64 commented on Mar 9, 2017

    @refi64
    Contributor

    Oof, this one's a mess...more of the errors were from 9406886, but there are still some that haven't come up yet...

  7. refi64 commented on Mar 9, 2017

    @refi64
    Contributor

    Around half of the errors were from, bizarrely enough, 3cc5201.

    So, to sum it up:

    • 9496d6f started the trouble:

      course/content.py:1445: error: object has no attribute "preview_git_commit_sha"
      course/content.py:1446: error: object has no attribute "preview_git_commit_sha"
      course/utils.py:533: error: object has no attribute "preview_git_commit_sha"
      course/utils.py:534: error: object has no attribute "preview_git_commit_sha"
      course/utils.py:583: error: object has no attribute "permissions"
      course/enrollment.py:129: error: object has no attribute "roles"
      course/views.py:156: error: object has no attribute "has_permission"
      course/flow.py:1264: error: object has no attribute "get_most_recent_grade"
      
    • 9406886 changed the objects to <uninhabited>:

      course/content.py:1445: error: <uninhabited> has no attribute "preview_git_commit_sha"
      course/content.py:1446: error: <uninhabited> has no attribute "preview_git_commit_sha"
      course/utils.py:533: error: <uninhabited> has no attribute "preview_git_commit_sha"
      course/utils.py:534: error: <uninhabited> has no attribute "preview_git_commit_sha"
      course/utils.py:583: error: <uninhabited> has no attribute "permissions"
      course/enrollment.py:129: error: <uninhabited> has no attribute "roles"
      course/views.py:156: error: <uninhabited> has no attribute "has_permission"
      course/flow.py:1264: error: <uninhabited> has no attribute "get_most_recent_grade"
      
    • 3cc5201 somehow just made it all worse:

      course/content.py:877: error: <uninhabited> has no attribute "id"
      course/content.py:1445: error: <uninhabited> has no attribute "preview_git_commit_sha"
      course/content.py:1446: error: <uninhabited> has no attribute "preview_git_commit_sha"
      course/utils.py:179: error: <uninhabited> has no attribute "exam"
      course/utils.py:533: error: <uninhabited> has no attribute "preview_git_commit_sha"
      course/utils.py:534: error: <uninhabited> has no attribute "preview_git_commit_sha"
      course/utils.py:583: error: <uninhabited> has no attribute "permissions"
      course/enrollment.py:129: error: <uninhabited> has no attribute "roles"
      course/enrollment.py:143: error: <uninhabited> has no attribute "permissions"
      course/views.py:156: error: <uninhabited> has no attribute "has_permission"
      course/flow.py:416: error: <uninhabited> has no attribute "user"
      course/flow.py:633: error: <uninhabited> has no attribute "answer"
      course/flow.py:830: error: <uninhabited> has no attribute "get_most_recent_grade"
      course/flow.py:848: error: Unsupported left operand type for + (some union)
      course/flow.py:855: error: Unsupported left operand type for + (some union)
      course/flow.py:862: error: Unsupported left operand type for + (some union)
      course/flow.py:923: error: <uninhabited> has no attribute "is_submitted_answer"
      course/flow.py:924: error: <uninhabited> has no attribute "save"
      course/flow.py:1264: error: <uninhabited> has no attribute "get_most_recent_grade"
      
  8. refi64 commented on Mar 9, 2017

    @refi64
    Contributor

    Also, I can confirm that 9496d6f was the root cause; temporarily reverting it made the errors go away.

  9. gvanrossum commented on Mar 9, 2017

    @gvanrossum
    Member

    Thanks for the great investigation! Hopefully Jukka knows how to fix it.

  10. refi64 commented on Mar 9, 2017

    @refi64
    Contributor

    Reduced test case:

    # Run mypy with --strict-optional
    from typing import Any, Optional
    
    class A(Any): pass
    
    def f(a: Optional[A]):
        if a is not None:
            reveal_type(a)

    (The Any stemmed from a class inside of a non-existent import, since --ignore-missing-imports was passed).

    Ironically enough, the bad commit's message says:

    In particular, this helps with classes that have Any base classes.

    :/

  11. refi64 commented on Mar 9, 2017

    @refi64
    Contributor

    Also, this was caused by the same commit:

    from typing import Any, Union
    
    class A(Any): pass
    class B: pass
    
    def f(a: Union[A, B]):
        if not isinstance(a, B):
            reveal_type(a)  # Union[<ERROR>, <ERROR>]
  12. JukkaL commented on Mar 10, 2017

    @JukkaL
    Collaborator

    Oh well, I knew that the bad commit was only a partial fix, but I didn't foresee these problems. A more complete fix that I was working on caused many problems with internal Dropbox code. The bad commit fixed other urgent issues so just reverting it is not a good option. I'll look at finishing up the more complete fix.

  13. self-assigned this
    on Mar 10, 2017
  14. ddfisher commented on Mar 14, 2017

    @ddfisher
    Collaborator

    Well, one problem is we need to kill this:

             if any(isinstance(typ, AnyType) for typ in items):
                  return AnyType()
  15. JukkaL commented on Mar 14, 2017

    @JukkaL
    Collaborator

    @ddfisher Yup, that's gone in my private branch.

  16. added 2 commits that reference this issue on Mar 19, 2017
    c6fd9a6
    dc62a99
  17. added 2 commits that reference this issue on Mar 29, 2017
    67cda6e
    bf20f49
  18. JukkaL commented on Apr 4, 2017

    @JukkaL
    Collaborator

    I think that this is still open because the fix was reverted.

  19. reopened this on Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions