Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Mapping and MutableMapping use the same example argument in docs #7617

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
MarcoGorelli opened this issue Oct 3, 2019 · 2 comments · Fixed by #7620
Closed

Mapping and MutableMapping use the same example argument in docs #7617

MarcoGorelli opened this issue Oct 3, 2019 · 2 comments · Fixed by #7620

Comments

@MarcoGorelli
Copy link
Contributor

The cheat sheet from the docs shows the following:

# Mapping describes a dict-like object (with "__getitem__") that we won't
# mutate, and MutableMapping one (with "__setitem__") that we might
def f(my_dict: Mapping[int, str]) -> List[int]:
    return list(my_dict.keys())

f({3: 'yes', 4: 'no'})

def f(my_mapping: MutableMapping[int, str]) -> Set[str]:
    my_mapping[5] = 'maybe'
    return set(my_mapping.values())

f({3: 'yes', 4: 'no'})

In both cases, the argument passed to f is a dict, though in one case the argument is annotated as Mapping and in the other MutableMapping.

From this example, it might not be clear to a beginner when to use Mapping over MutableMapping.

@msullivan
Copy link
Collaborator

Good point! Would you like to submit a PR improving it?

@MarcoGorelli
Copy link
Contributor Author

Sure! I'll get to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants