Skip to content

fix crash when serializing a type-ignored property setter #3493

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

Merged
merged 3 commits into from
Jun 3, 2017

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Jun 2, 2017

This fixes two issues from #3491: a crash in serialization and an incorrect error "Function is missing a type annotation for one or more arguments". Both had the same root cause; we were skipping semantic analysis for the function body if mypy was unhappy with the property.setter decorator.

This fixes the crash from python#3491. I wasn't able to reproduce the
crash in a test, even with '# flags: --incremental', so I'm
not adding any new tests. Do I need some special flags to make
tests write the cache?
@gvanrossum
Copy link
Member

I think only tests in check-incremental.test and tests whose name ends in 'Incremental' exercise serialization.

@gvanrossum
Copy link
Member

So please add such a test.

Turns out the cache isn't written if there is any error,
and I had a reveal_type which counts as an error.

The change fixes both bugs from the original issue:
- Without --disallow-untyped-defs, it no longer crashes during
  cache serialization.
- With --disallow-untyped-defs, it no longer produces a spurious
  error because "self" doesn't have an annotation.
@JelleZijlstra
Copy link
Member Author

Thanks, it turns out the issue was that the cache isn't written when there is an error in the file, and I had a reveal_type(), which counts as an error.

In other news, it turns out that this PR also fixes the other bug reported in #3491 (the spurious "missing type annotation" error). Therefore, I added tests both with and without --disallow-untyped-defs.

@@ -564,9 +564,10 @@ def analyze_property_with_multi_part_definition(self, defn: OverloadedFuncDef) -
first_item.var.is_settable_property = True
# Get abstractness from the original definition.
item.func.is_abstract = first_item.func.is_abstract
item.func.accept(self)
else:
self.fail("Decorated property not supported", item)
Copy link
Member

Choose a reason for hiding this comment

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

This should also be fixed (it's in a sense the true reason for the issue). But not in this PR.

Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Great work. I'll merge once tests pass again after my PEP 8 change.

@gvanrossum gvanrossum merged commit b5fa5d2 into python:master Jun 3, 2017
@gvanrossum
Copy link
Member

Oh, sorry, I should have copied your updated PR description. Oh well.

@JelleZijlstra JelleZijlstra deleted the fix3491 branch June 3, 2017 04:00
carljm added a commit to carljm/mypy that referenced this pull request Jun 3, 2017
* master:
  fix crash when serializing a type-ignored property setter (python#3493)
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.

2 participants