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 right_type precision #15766

Closed
wants to merge 2 commits into from
Closed

Conversation

jslambda
Copy link

@jslambda jslambda commented Jul 26, 2023

This is a fix for #15534

Without this fix mypy reports error (Incompatible return value type (got "str | None", expected "str")) for the following cases:

def foo(x: Dict[str, str]) -> str: return x.get("a") or x.get("b", "c")
def bar(x: Dict[str, str]) -> str: return None or  x.get("c","d")

I would appreciate your feedback

Best regards,
Hamid Alavi Toussi

@JelleZijlstra
Copy link
Member

Please add a new test case to clarify what this is fixing.

@jslambda
Copy link
Author

Hi @JelleZijlstra
This is a fix for #15534
Which file in the mypy source would be a good place for adding a test case for this kind of problem?

@github-actions

This comment has been minimized.

@jslambda
Copy link
Author

Hi @JelleZijlstra
I have added a test case:
99d9052

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

sublime_debugger (https://github.com/daveleroy/sublime_debugger)
+ modules/ui/layout.py:156: error: Unsupported operand types for - ("None" and "float")  [operator]
+ modules/ui/layout.py:156: note: Left operand is of type "float | None"

@AlexWaygood
Copy link
Member

AlexWaygood commented Jul 28, 2023

Thanks for the PR @jslambda! I just closed #15534, as the issue with dict.get has been resolved by a recent typeshed change (python/typeshed#10293). Will this PR be useful for other reasons, do you think, or should it be closed?

@jslambda
Copy link
Author

Hi @AlexWaygood . Thanks for the comment. I'm not aware of other cases which are fixed by this PR so the PR can be closed.
Is there any other PR for merging the typeshed fix to mypy? I can still reproduce the error on da1853f

@AlexWaygood
Copy link
Member

Is there any other PR for merging the typeshed fix to mypy? I can still reproduce the error on da1853f

We do a typeshed sync once a fortnight. The next one is due in the next few days, so not long to wait!

Thanks for the contribution, @jslambda!

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.

3 participants