Skip to content
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

Request: Optional config to warn when a parameter annotation could use Mapping instead of Dict or Sequence instead of List #8484

Open
ckarnell opened this issue Mar 3, 2020 · 1 comment

Comments

@ckarnell
Copy link
Contributor

ckarnell commented Mar 3, 2020

  • Are you reporting a bug, or opening a feature request?
    Feature request

Basically, I think it would be nice if mypy could warn when the user could be giving their function immutable versions of the argument types instead of mutable ones. For example:

def len_greater_than_three(input_list: List[int]) -> bool: # Warning: Could use read only type Sequence instead of List for parameter 1.
    return len(input_list) > 3

Being prompted to use immutable types when you're not mutating the input could improve the usability of mypy quite a bit since it would result in functions who's parameters are covariant much more often. It's also convenient to know when a function isn't mutating its arguments based on its annotation, and the desire to default to using immutable types wherever possible probably makes sense for a lot of users.

@ilevkivskyi
Copy link
Member

In principle think can be a useful feature. But I think it is relatively low priority.

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

No branches or pull requests

2 participants