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 None assignments with fine-grained cache #11574

Merged

Conversation

christianbundy
Copy link
Contributor

@christianbundy christianbundy commented Nov 17, 2021

Description

Problem: When using the fine-grained cache, we raise an assertion in
some situations when an attribute is defined as None.

Solution: Remove truthiness check to ensure that None is an allowed
type.

Fixes: #8682
Fixes: #11456

Test Plan

I've added a test that crashes in master and passes when this patch is applied.

cc: @sobolevn

Problem: When using the fine-grained cache, we raise an assertion in
some situations when an attribute is defined as `None`.

Solution: Remove truthiness check to ensure that `None` is an allowed
type.

Fixes: python#8682
Fixes: python#11456
@sobolevn
Copy link
Member

Related: #11561

Similar problem.

@sobolevn
Copy link
Member

I'm not sure how to encode this as an automated test.

Take a look at test-data/unit/fine-grained.test file 🙂

This test fails in `master` and passes when the patch is applied.
@christianbundy
Copy link
Contributor Author

Thanks! I was able to add a test, repro the crash in master, and confirm that the test no longer fails in my branch.

I think this is good to go. ✅

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thanks, awesome work narrowing this down.

I don't know all the cases when lvalue.node.type is None and I'm not really familiar with the fine grained stuff. That is, I'm not sure I understand exactly what we should return here, e.g. returning UninhabitedType() instead of NoneType() also fixes the crash

@github-actions

This comment has been minimized.

@christianbundy
Copy link
Contributor Author

UninhabitedType() instead of NoneType()

Is this preferable? I don't have an opinion either way, so whichever is more likely to be merged works for me.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Dec 8, 2021

Reading through the code, I think it doesn't make a practical difference, since TypeTriggersVisitor does the same thing for NoneType and UninhabitedType.
However, I think I'd still prefer using UninhabitedType, since it matches what we do in the else branch and earlier in the function, so I made that change :-)

Thanks again, tricky issue to narrow down!

mypy/server/deps.py Outdated Show resolved Hide resolved
@christianbundy
Copy link
Contributor Author

Sounds good to me, thank you!

@hauntsaninja hauntsaninja merged commit 1393e3f into python:master Dec 8, 2021
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this pull request Jan 20, 2022
Problem: When using the fine-grained cache, we raise an assertion in
some situations when an attribute is defined as `None`.

Solution: Remove truthiness check to ensure that `None` is an allowed
type.

Fixes: python#8682
Fixes: python#11456
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.

Crash on latest Django Project with dmypy AssertionError mypy/server/deps.py:495
4 participants