Skip to content

Use customized error message for %c interpolation #10875

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

Merged
merged 7 commits into from
Jul 26, 2021

Conversation

97littleleaf11
Copy link
Collaborator

@97littleleaf11 97littleleaf11 commented Jul 26, 2021

Description

This PR is a follow-up to #10869.

  • Add more tests for %c interpolation
  • The error msg of mypy now is bassically the same as CPython. We offer hints for incompatible types.
  • Change type of Checkers from Tuple[Callable[[Expression], None], Callable[[Type], None]] to Tuple[Callable[[Expression], None], Callable[[Type], bool]]. check_expr can get a False from check_type and stop generating same error message.

Test Plan

Adds several new test cases.

CPython behaviors:

'%c' % b''   # E: "%c" requires int or char
'%c' % b'ab' # E: "%c" requires int or char
b'%c' % b''   # E: "%c" requires int or char
b'%c' % b'aa' # E: "%c" requires int or char

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable. Since %c seems to be used extremely rarely, I don't recommend putting more effort into improving it.

@JukkaL JukkaL merged commit bc1dc95 into python:master Jul 26, 2021
@97littleleaf11 97littleleaf11 deleted the mypy-bytes-c branch July 26, 2021 18:45
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