Skip to content

from __future__ import annotations doesn't ignore annotations correctly #3236

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
Starwort opened this issue Nov 8, 2019 · 4 comments
Closed

Comments

@Starwort
Copy link

Starwort commented Nov 8, 2019

Steps to reproduce

  1. Use code
from __future__ import annotations
from collections import defaultdict
squares: defaultdict[tuple, int] = defaultdict(lambda: 999999)
  1. Run pylint on this code
  2. E1136: Value 'defaultdict' is unsubscriptable (unsubscriptable-object)

Current behaviour

Throws E1136: Value 'defaultdict' is unsubscriptable (unsubscriptable-object)

Expected behaviour

Ignores it (as Python itself does)

pylint --version output

pylint 2.4.3
astroid 2.3.1
Python 3.8.0 (default, Oct 15 2019, 14:05:58) 
[GCC 7.4.0]
@PCManticore
Copy link
Contributor

Thanks for opening an issue! This error makes sense somewhat as you should use typing.DefaultDict instead. Even mypy emits the same warning with:

a.py:3: error: "defaultdict" is not subscriptable, use "typing.DefaultDict" instead

While Python ignores the variable annotations, they can still contain errors such as this one.

@Starwort
Copy link
Author

Starwort commented Nov 10, 2019

I submitted a near-identical issue to mypy, as the tools should still accept these as valid, even if they aren't preferred - as they are valid typehints. Disagree with closure

Also note that mypy are planning to add this functionality (priority 1 - normal)

@Starwort
Copy link
Author

Furthermore, here is the issue, complete with MyPy's feature and priority tags, that I submitted to MyPy (along with confirmation this is being added; i.e. MyPy will stop reporting this error).
python/mypy#7907 (comment)

@Starwort
Copy link
Author

Starwort commented Dec 3, 2019

https://www.python.org/dev/peps/pep-0585/
PEP 585 explicitly allows this behaviour. I'd like this issue reopened accordingly; I may open a new issue if I think this isn't noticed :P

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

2 participants