Skip to content

No overload variant of "get" … for os.environ with unicode_literals #1274

Closed
@posita

Description

@posita

This works:

# test.py
import os
print('PWD: {}'.format(os.environ.get('PWD', '<not set>')))
$ python --version
Python 2.7.13
$ python test.py
PWD: …
$ python3 --version
Python 3.6.0
$ python3 test.py
PWD: …
$ mypy test.py
$ mypy --py2 test.py

This fails validation with --py2:

# test_unicode_literals.py
from __future__ import unicode_literals  # this is new
import os
print('PWD: {}'.format(os.environ.get('PWD', '<not set>')))
$ python test_unicode_literals.py
PWD: …
$ python3 test_unicode_literals.py
PWD: …
$ mypy test_unicode_literals.py
$ mypy --py2 test_unicode_literals.py
test_unicode_literals.py:3: error: No overload variant of "get" of "Mapping" matches argument types [builtins.unicode, builtins.unicode]

See stdlib/2/os/__init__.pyi#L67.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions