KEMBAR78
Use customized error message for %c interpolation by 97littleleaf11 · Pull Request #10875 · python/mypy · GitHub
Skip to content

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