Skip to content

"No overload variant of sub" Issue with re.compile after upgrading to mypy 0.4 #1492

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
timabbott opened this issue May 5, 2016 · 4 comments

Comments

@timabbott
Copy link

On upgrading to mypy 0.4 I get this new error:

/home/tabbott/foo.py:4: error: No overload variant of "sub" matches argument types [typing.Pattern[builtins.str*], builtins.str, builtins.str]

when using a compiled regular expression:

content = "test"
import re
quote_re = re.compile(r'{quote}(.*?){quote}', re.DOTALL)
content = re.sub(quote_re, r'~~~ quote\n\1\n~~~', content)

Haven't had a chance to investigate whether this is caused be a change in typeshed or mypy itself.

@gvanrossum
Copy link
Member

That's strange. Assuming you're using --py2 mode (there's no overload in the Python 3 stub for re.pyi). The stdlib/2.7/re.pyi hasn't changed since your change 21c90d5 in January. It looks like the spec for sub() is wrong, it doesn't allow Pattern[AnyStr] for the pattern arg. I'm guessing that some bug in overload checking was fixed that surfaced this. The stub needs to be fixed.

@rwbarton
Copy link
Contributor

rwbarton commented May 5, 2016

Oh, I think one of my changes made it so that type variables with value restriction in overloads would only match types that are a subtype of the union of the possible values of the type variable. So Pattern[str] no longer matches Union[str, unicode]. Not sure why the statement type checked in the first place, maybe #1322?

@timabbott
Copy link
Author

OK, I think this turned out to be just a stub issue, so we can close it, right?

@gvanrossum
Copy link
Member

Yup.

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