-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Rename variable to avoid mypy type error #23669
Conversation
I'd like either @Hexcles or @gsnedders to look at this, as their mypy knowledge far exceeds mine. |
Note that this didn't start complaining until #23644, so it may be that there is some problem here and this is the wrong fix With #23644 reverted, I get:
With that change, |
Ok yes, reverting #23644 and doing some bisecting I narrowed this to the change in type of |
What are the revealed types with it, but without the str call? I'm slightly surprised to see |
Not sure if I am misunderstanding, but that PR added the |
Pretty sure I'm misunderstanding now, given:
So if #23644 caused it to flip to |
Soooo I renamed
I think mypy is getting confused with the earlier declarations of |
jgraham points me to: python/mypy#1174 |
So options are: i. Do the type annotation like this PR does - it works today to nudge mypy into realizing the new type of 'key', but not guaranteed to work always I guess? I'm open to opinions. I probably lean to (ii). |
I think I prefer i to iii in that order. But I'm happy with i or ii and less with iii. |
Great investigation, folks! I think the root cause here is indeed the redefinition of |
Question: was this just a warning instead of an error from mypy? (I'm wondering how #23644 passed.) |
Because that PR wrapped |
And you noticed when reviewing the code?
…On Mon., May 18, 2020, 19:06 Stephen McGruer, ***@***.***> wrote:
Question: was this just a warning instead of an error from mypy? (I'm
wondering how #23644
<#23644> passed.)
Because that PR wrapped key in str(key) explicitly.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23669 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAK6ZDCG3CXCGMSR4J3H2XLRSG5NXANCNFSM4NEHT3BQ>
.
|
@foolip did: #23644 (comment) |
Reusing variables can cause a mypy type error (python/mypy#1174).
This previously went unnoticed because the previous and current use of
key
wasstr
, but in#23644 the previous use was retyped to
Text
and as such caused a unicode-vs-str type error in mypy.