-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
call-overload error on environ.pop("…", default="…")
#11831
Comments
Works around <python/mypy#11831>.
* build(deps-dev): Bump mypy from 0.910 to 0.930 Bumps [mypy](https://github.com/python/mypy) from 0.910 to 0.930. - [Release notes](https://github.com/python/mypy/releases) - [Commits](python/mypy@v0.910...v0.930) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * fix: Work around missing tomli build dependency * fix: Ignore mypy error Works around <python/mypy#11831>. Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Victor Engmark <vengmark@linz.govt.nz>
Similar problems happen with
With the following: cat > papersize.py
import os
print(os.environ.get('PAPERSIZE', default='fool')) Then: mypy papersize.py
papersize.py:3: error: No overload variant of "get" of "Mapping" matches argument types "str", "str"
papersize.py:3: note: Possible overload variants:
papersize.py:3: note: def get(self, key: str) -> Optional[str]
papersize.py:3: note: def [_T] get(self, str, Union[str, _T]) -> Union[str, _T] I've reproduced with I think these problems might be related to this change in typeshed here: python/typeshed#5772 which is an attempt to solve this error: python/typeshed#5771 What I'm wondering is what Python developers are meant to experience with this functionality? Use the |
For anyone looking back on this issue, this is still failing as of |
I got this error today in slightly different circumstances. mypy 1.2.0, python 3.10.10. The example given in this issue does not error for me: $ mypy --strict <(echo 'from os import environ; environ.pop("…", default="…")')
Success: no issues found in 1 source file However, a modification does: $ mypy --strict <(echo '{}.pop("…", default=None)')
/proc/self/fd/11:1: error: No overload variant of "pop" of "dict" matches argument types "str", "None" [call-overload]
/proc/self/fd/11:1: note: Possible overload variants:
/proc/self/fd/11:1: note: def pop(self, <nothing>, /) -> <nothing>
/proc/self/fd/11:1: note: def [_T] pop(self, <nothing>, _T, /) -> _T
Found 1 error in 1 file (checked 1 source file) Interestingly, calling pop on a type annotated variable, plus passing $ mypy --strict <(echo 'a: dict[str, str] = {}; a.pop("…", None)')
Success: no issues found in 1 source file If you keep $ mypy --strict <(echo 'a: dict[str, str] = {}; a.pop("…", default=None)')
/proc/self/fd/11:1: error: No overload variant of "pop" of "dict" matches argument types "str", "None" [call-overload]
/proc/self/fd/11:1: note: Possible overload variants:
/proc/self/fd/11:1: note: def pop(self, str, /) -> str
/proc/self/fd/11:1: note: def [_T] pop(self, str, Union[str, _T], /) -> Union[str, _T]
Found 1 error in 1 file (checked 1 source file) |
mypy's correct here:
|
Bug Report
It's all in the title.
As far as I can tell it's not a duplicate of #10152, because I'm not dealing with
TypeVar
s, or #3750, because I'm not doing any overloading myself.To Reproduce
Expected Behavior
This should succeed. This is a regression since 0.910.
Your Environment
--strict
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: