-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
plugins: delete open plugin #9275
Conversation
Draft PR because we'll need python/typeshed#4407 to be merged and synced before tests will 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.
I expect this is going to make a lot of people unhappy — being more strict it will cause new failures in people’s CI. @JukkaL what do you think? Would it be bad for the Dropbox build?
finally: | ||
if not f.closed: | ||
f.close() | ||
support.unlink(support.TESTFN) |
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.
Is it safe to drop the finally clause with unlink?
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.
It wouldn't be, if this code were ever executed! We've talked about entirely getting rid of the stdlib samples before (e.g., in #8838), so I didn't try very hard to preserve them.
It's unclear, but I wouldn't be surprised if this requires quite a few changes, as there are thousands of calls to |
@@ -243,10 +243,10 @@ def _write_out_report(self, | |||
f.write(separator + '\n') | |||
for row_values in rows: | |||
r = ("{:>{}}" * len(widths)).format(*itertools.chain(*zip(row_values, widths))) | |||
f.writelines(r + '\n') | |||
f.write(r + '\n') |
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.
What made this change necessary?
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 looks like it fixes a bug! writelines takes a sequence of strings, not a single string (though because a string is a sequence of strings and writelines just writes the concatenation of the items it worked :-).
Though I'm not sure how the change found this bug -- does the TextIoWriter class (or whatever is used) not have writelines?
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.
We now infer f as TextIOWrapper. TextIOWrapper and TextIOBase take List[str]
for writelines
in typeshed. Maybe that signature should be loosened though.
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.
Yes, I think that should be Iterable[str]
. I just tried in 3.6 and TextIOWrapper.writelines accepts at least tuples and generator expressions.
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.
And it looks like the perennial "str is a iterable of str" bug is benign in this case, so there's not really any downside to the looser signature.
All green now! I'm not sure what will become of this PR, but it's ready to find out! |
I wrote a script that democratises the ability to evaluate changes like this: https://github.com/hauntsaninja/mypy_primer |
Here are the results for this PR:
If we loosen the type of writelines in typeshed (as we should), this brings the count to five errors against (one of which is fixed in this PR) and one error for out of a couple million lines of code. The five errors against are arguably "by design", since |
e0f4960
to
98033ac
Compare
Improvements to typeshed types using literals should have rendered this unnecessary.
Since errors shouldn't be used with binary modes. Maybe should just delete?
98033ac
to
8502699
Compare
This came up in python/mypy#9275
This came up in python/mypy#9275 Co-authored-by: hauntsaninja <>
There's a competing "delete open plugin" from earlier: #7794. Do you have any opinions on this one versus that, @hauntsaninja |
Yeah, I noticed the duplication a couple weeks ago when cleaning up some old PRs :-/ The big difference is that that PR no longer gets rid of the open plugin, because of https://github.com/python/mypy/pull/7794/files#discussion_r342519954 It's also not clear to me why that PR doesn't necessitate some of the changes that I've made here. It's possible merging in a newer typeshed into that PR would surface those complaints (although I'll note that I changed the writelines type in typeshed in python/typeshed#4642) |
@JukkaL @ilevkivskyi what is the damage like for this PR at Dropbox? |
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: mypy_primer (https://github.com/hauntsaninja/mypy_primer)
+ mypy_primer.py:118: error: Unused "type: ignore" comment
+ mypy_primer.py:119: error: Item "None" of "Optional[bytes]" has no attribute "count"
mypy (https://github.com/python/mypy)
+ mypyc/build.py:311: error: Incompatible types in assignment (expression has type "BufferedWriter", variable has type "BufferedReader") [assignment]
pip (https://github.com/pypa/pip)
+ src/pip/_internal/req/req_uninstall.py:623: error: Incompatible types in assignment (expression has type "BufferedWriter", variable has type "BufferedReader")
+ src/pip/_internal/operations/install/wheel.py:107: error: Incompatible types in assignment (expression has type "BufferedWriter", variable has type "BufferedReader")
zulip (https://github.com/zulip/zulip)
+ tools/setup/generate_integration_bots_avatars.py:54: error: Incompatible types in assignment (expression has type "BufferedWriter", variable has type "BufferedReader") [assignment]
|
Issues that this would fix are reported fairly regularly. Given how long this PR has been lying around, and that the mypy_primer output doesn't look unworkable, I'm going to try asking for forgiveness on this merge :-) |
Upgrade mypy to 0.971, which is the last version that supports Python 3.6 (the oldest Python version that we currently run on the CI). This fixes the error ``` tests/scripts/analyze_outcomes.py:117: error: Incompatible return value type (got "IO[Any]", expected "TextIO") tests/scripts/analyze_outcomes.py:119: error: Incompatible return value type (got "IO[Any]", expected "TextIO") ``` As far as I can tell the fix is python/mypy#9275 which was released in mypy 0.940. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Upgrade mypy to 0.971, which is the last version that supports Python 3.6 (the oldest Python version that we currently run on the CI). This fixes the error ``` framework/scripts/mbedtls_framework/outcome_analysis.py:119: error: Incompatible return value type (got "IO[Any]", expected "TextIO") framework/scripts/mbedtls_framework/outcome_analysis.py:121: error: Incompatible return value type (got "IO[Any]", expected "TextIO") ``` As far as I can tell the fix is python/mypy#9275 which was released in mypy 0.940. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Upgrade mypy to 0.971, which is the last version that supports Python 3.6 (the oldest Python version that we currently run on the CI). This fixes the error ``` framework/scripts/mbedtls_framework/outcome_analysis.py:119: error: Incompatible return value type (got "IO[Any]", expected "TextIO") framework/scripts/mbedtls_framework/outcome_analysis.py:121: error: Incompatible return value type (got "IO[Any]", expected "TextIO") ``` As far as I can tell the fix is python/mypy#9275 which was released in mypy 0.940. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Upgrade mypy to 0.971, which is the last version that supports Python 3.6 (the oldest Python version that we currently run on the CI). This fixes the error ``` framework/scripts/mbedtls_framework/outcome_analysis.py:119: error: Incompatible return value type (got "IO[Any]", expected "TextIO") framework/scripts/mbedtls_framework/outcome_analysis.py:121: error: Incompatible return value type (got "IO[Any]", expected "TextIO") ``` As far as I can tell the fix is python/mypy#9275 which was released in mypy 0.940. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Upgrade mypy to 0.971, which is the last version that supports Python 3.6 (the oldest Python version that we currently run on the CI). This fixes the error ``` framework/scripts/mbedtls_framework/outcome_analysis.py:119: error: Incompatible return value type (got "IO[Any]", expected "TextIO") framework/scripts/mbedtls_framework/outcome_analysis.py:121: error: Incompatible return value type (got "IO[Any]", expected "TextIO") ``` As far as I can tell the fix is python/mypy#9275 which was released in mypy 0.940. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Upgrade mypy to 0.971, which is the last version that supports Python 3.6 (the oldest Python version that we currently run on the CI). This fixes the error ``` framework/scripts/mbedtls_framework/outcome_analysis.py:119: error: Incompatible return value type (got "IO[Any]", expected "TextIO") framework/scripts/mbedtls_framework/outcome_analysis.py:121: error: Incompatible return value type (got "IO[Any]", expected "TextIO") ``` As far as I can tell the fix is python/mypy#9275 which was released in mypy 0.940. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Upgrade mypy to 0.971, which is the last version that supports Python 3.6 (the oldest Python version that we currently run on the CI). This fixes the error ``` framework/scripts/mbedtls_framework/outcome_analysis.py:119: error: Incompatible return value type (got "IO[Any]", expected "TextIO") framework/scripts/mbedtls_framework/outcome_analysis.py:121: error: Incompatible return value type (got "IO[Any]", expected "TextIO") ``` As far as I can tell the fix is python/mypy#9275 which was released in mypy 0.940. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Upgrade mypy to 0.971, which is the last version that supports Python 3.6 (the oldest Python version that we currently run on the CI). This fixes the error ``` framework/scripts/mbedtls_framework/outcome_analysis.py:119: error: Incompatible return value type (got "IO[Any]", expected "TextIO") framework/scripts/mbedtls_framework/outcome_analysis.py:121: error: Incompatible return value type (got "IO[Any]", expected "TextIO") ``` As far as I can tell the fix is python/mypy#9275 which was released in mypy 0.940. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Improvements to typeshed types using literals should have rendered this
unnecessary.