Skip to content

Conversation

@AlexWaygood
Copy link
Member

There are many places in mypy's code where casts are currently used unnecessarily. These can be replaced with asserts, which are much more type-safe, and more mypyc-friendly.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

AlexWaygood added a commit to AlexWaygood/mypy that referenced this pull request Mar 11, 2023
Split off from python#14860, since this one is a no-brainer
JelleZijlstra pushed a commit that referenced this pull request Mar 11, 2023
Split off from #14860, since this one is a no-brainer.

`args[0]` has just been narrowed to be of type `StrExpr` in the lines
immediately above, and `args` is the same as `call.args`.
@JelleZijlstra JelleZijlstra self-assigned this Mar 11, 2023
@AlexWaygood
Copy link
Member Author

AlexWaygood commented Mar 11, 2023

Moving this back into draft: looking at this again, I think you're right; we can fairly easily improve the signature of expand_type, and by doing so remove the need for many of these asserts.

@AlexWaygood AlexWaygood marked this pull request as draft March 11, 2023 15:21
@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member Author

Moving this back into draft: looking at this again, I think you're right; we can fairly easily improve the signature of expand_type, and by doing so remove the need for many of these asserts.

Here's a better solution for the expand_type/expand_type_by_instance ones:

@AlexWaygood AlexWaygood marked this pull request as ready for review March 11, 2023 16:33
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra merged commit fddd5c5 into python:master Mar 11, 2023
@AlexWaygood AlexWaygood deleted the fewer-casts branch March 11, 2023 17:44
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