-
Notifications
You must be signed in to change notification settings - Fork 13
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
Attempt to make the test suite pass under mypy 1.0.0 #89
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fb1accd
Test against mypy 1.0.0
3877ca9
Hide error codes
da1d0fb
Mark interface method definitions as abstract
2bd8dfd
Update interface_unknown_inherit error message
7c42399
Fix overload-readme sample
91ae304
Fix contextmanager sample
d3697b8
Mark decorated interface functions as abstract
4b4e929
Remove faulty decorator logic
kedder 5e64237
Provide a nonempty body in interface_meta example
kedder 7c07bff
Remove the staticmethod from IBookmark
kedder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,9 @@ def make_simple_type( | |
} | ||
|
||
|
||
HACK_IS_ABSTRACT_NON_PROPAGATING = -12345678 | ||
|
||
|
||
class ZopeInterfacePlugin(Plugin): | ||
def __init__(self, options: Options): | ||
super().__init__(options) | ||
|
@@ -479,6 +482,9 @@ def _analyze_zope_interface( | |
replacement = self._adjust_interface_function(api, cls.info, item) | ||
elif isinstance(item, OverloadedFuncDef): | ||
replacement = self._adjust_interface_overload(api, cls.info, item) | ||
elif isinstance(item, Decorator): | ||
replacement = item | ||
replacement.func = self._adjust_interface_function(api, cls.info, item.func) | ||
else: | ||
continue | ||
|
||
|
@@ -520,6 +526,27 @@ def _adjust_interface_function( | |
func_def.arg_kinds.insert(0, ARG_POS) | ||
func_def.arguments.insert(0, selfarg) | ||
|
||
# 1: We want mypy to consider this method abstract, so that it allows the | ||
# method to have an empty body without causing a warning. | ||
# 2: We want mypy to consider the interface class NOT abstract, so we can use the | ||
# "adaption" pattern. | ||
# Unfortunately whenever mypy sees (1) it will mark the class as abstract, | ||
# forcing (2) to be false. This seems to be a change in mypy 0.990, namely | ||
# https://github.com/python/mypy/pull/13729 | ||
# | ||
# Mypy 1.0.0: | ||
# - allows empty bodies for abstract methods in mypy/checker.py:1240 | ||
# by testing if | ||
# abstract_status != NOT_ABSTRACT. | ||
# - marks classes as abstract based on their methods in | ||
# mypy/semanal_classprop.py:79 by testing if | ||
# abstract_status in (IS_ABSTRACT, IMPLICITLY_ABSTRACT) | ||
# | ||
# Thus we can make (1) and (2) true by setting abstract_status to some value | ||
# distinct from these three NOT_ABSTRACT, IS_ABSTRACT and IMPLICITLY_ABSTRACT. | ||
# These are presently the integers 0, 1, and 2 defined in mypy/nodes.py:738-743. | ||
func_def.abstract_status = HACK_IS_ABSTRACT_NON_PROPAGATING | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very unorthodox, but if it will let us to upgrade to mypy-1.0, I'm all for it! :) |
||
|
||
return func_def | ||
|
||
def _adjust_interface_overload( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be causing error in the description. What this change is designed for?
The following patch to your branch makes all tests pass:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, actually my patch is stupid, interface cannot have an implementation, disregard it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That
create
method didn't make too much sense anyways. I suggest this, unless there's something important about handling decorators:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
IBookmark
example that you cite. I thought the staticmethod was intended to be part of theIBookmark
interface, so that classes which implement it would have to define their owncreate
method.If that's not the case then let's apply your patch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't even think interfaces can define static methods... At least it doesn't make sense to me today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I see, the test doesn't even make use of
create
. Let's try the second patch.