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

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

Closed
inducer opened this issue Mar 8, 2017 · 15 comments
Assignees
Labels
bug mypy got something wrong topic-strict-optional

Comments

@inducer
Copy link

inducer commented Mar 8, 2017

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).

@gvanrossum
Copy link
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...

@gvanrossum gvanrossum added the bug mypy got something wrong label Mar 8, 2017
@gvanrossum
Copy link
Member

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

@inducer
Copy link
Author

inducer commented Mar 8, 2017

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

@refi64
Copy link
Contributor

refi64 commented Mar 9, 2017

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

@refi64
Copy link
Contributor

refi64 commented Mar 9, 2017

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

@refi64
Copy link
Contributor

refi64 commented Mar 9, 2017

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

@refi64
Copy link
Contributor

refi64 commented Mar 9, 2017

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"
    

@refi64
Copy link
Contributor

refi64 commented Mar 9, 2017

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

@gvanrossum
Copy link
Member

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

@refi64
Copy link
Contributor

refi64 commented Mar 9, 2017

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.

:/

@refi64
Copy link
Contributor

refi64 commented Mar 9, 2017

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>]

@JukkaL
Copy link
Collaborator

JukkaL commented Mar 10, 2017

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.

@JukkaL JukkaL self-assigned this Mar 10, 2017
@ddfisher
Copy link
Collaborator

Well, one problem is we need to kill this:

         if any(isinstance(typ, AnyType) for typ in items):
              return AnyType()

@JukkaL
Copy link
Collaborator

JukkaL commented Mar 14, 2017

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

JukkaL added a commit that referenced this issue Mar 19, 2017
JukkaL added a commit that referenced this issue Mar 21, 2017
JukkaL added a commit that referenced this issue Mar 29, 2017
The main change is that unions containing Any are no longer simplified
to just Any. Also union simplification now has a deterministic result unlike
previously, when result could depend on the order of items in a union
(this is true modulo remaining bugs).

This required changes in various other places to keep the existing
semantics, and resulted in some fixes to existing test cases. I also
had to fix some tangentially related minor bugs that were triggered
by the other changes.

We generally don't have fully constructed TypeInfos so
we can't do proper union simplification during semantic
analysis. Just implement simple-minded simplification that 
deals with the cases we care about.

Fixes #2978. Fixes #1914.
JukkaL added a commit that referenced this issue Mar 30, 2017
The main change is that unions containing Any are no longer simplified
to just Any. Also union simplification now has a deterministic result unlike
previously, when result could depend on the order of items in a union
(this is true modulo remaining bugs).

This required changes in various other places to keep the existing
semantics, and resulted in some fixes to existing test cases. I also
had to fix some tangentially related minor bugs that were triggered
by the other changes.

We generally don't have fully constructed TypeInfos so
we can't do proper union simplification during semantic
analysis. Just implement simple-minded simplification that 
deals with the cases we care about.

Fixes #2978. Fixes #1914.
@JukkaL
Copy link
Collaborator

JukkaL commented Apr 4, 2017

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

@JukkaL JukkaL reopened this Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-strict-optional
Projects
None yet
Development

No branches or pull requests

5 participants