Skip to content

unittest.TestCase.assertRegex should allow bytes #2312

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

Closed
bmerry opened this issue Jul 6, 2018 · 4 comments
Closed

unittest.TestCase.assertRegex should allow bytes #2312

bmerry opened this issue Jul 6, 2018 · 4 comments

Comments

@bmerry
Copy link
Contributor

bmerry commented Jul 6, 2018

The annotation for unittest.TestCase.assertRegex is currently

def assertRegex(self, text: str, regex: Union[str, Pattern[str]], msg: Any = ...) -> None: ...

However, it's also legal to use bytes, as long as both text and regex are bytes. This also affects assertNotRegex and assertRegexpMatches.

@gvanrossum
Copy link
Member

That should be an easy fix using generics, right? Can you submit a PR?

@JelleZijlstra
Copy link
Member

You may run into python/mypy#3644 though. In that case, you'll need to use overloads instead (one for bytes and one for str).

@bmerry
Copy link
Contributor Author

bmerry commented Jul 6, 2018

That should be an easy fix using generics, right? Can you submit a PR?

Sure, will give it a try next week.

bmerry added a commit to bmerry/typeshed that referenced this issue Jul 9, 2018
And also in assertNotRegex, assertRegexpMatches.

Closes python#2312.
@bmerry
Copy link
Contributor Author

bmerry commented Jul 9, 2018

I've submitted a PR. I gave it a quick test and didn't see any problems like #3644. The error messages in cases where one mixed bytes with str aren't the most informative (error: Value of type variable "AnyStr" of "assertRegex" of "TestCase" cannot be "object"), but it does get the right results.

gvanrossum pushed a commit that referenced this issue Jul 9, 2018
And also in assertNotRegex, assertRegexpMatches.

Closes #2312.
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this issue Jan 23, 2019
And also in assertNotRegex, assertRegexpMatches.

Closes python#2312.
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

No branches or pull requests

3 participants