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

PEP 585 runtime exceptions not recognized #1001

Closed
cdce8p opened this issue Feb 28, 2021 · 2 comments
Closed

PEP 585 runtime exceptions not recognized #1001

cdce8p opened this issue Feb 28, 2021 · 2 comments
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@cdce8p
Copy link

cdce8p commented Feb 28, 2021

Environment data

  • Language Server version: 2021.2.4
  • OS and version: MacOS 10.15.7
  • Python version: 3.8.8
  • typeCheckingMode: strict

Expected behaviour

The following examples should be invalid without from __future__ import annotations in Python 3.7 and 3.8.

import collections
import collections.abc
import contextlib
import re

var: collections.defaultdict[int, str]
var2: collections.abc.Iterable[int]  # and every other type from `collections.abc` (except `Hashable` and `Sized`)
var3: contextlib.AbstractContextManager[int]
var4: contextlib.AbstractAsyncContextManager[int]
var5: re.Pattern[str]
var6: re.Match[str]

https://docs.python.org/3/library/typing.html#corresponding-to-other-types-in-collections-abc

Actual behaviour

Pylance doesn't infer them as errors.
Interestingly collections.OrderedDict[int, str], ChainMap, Counter and deque are recognized correctly.

@erictraut
Copy link
Contributor

Thanks for the suggestion.

I was able to address this for collections.defaultdict, but I can't do anything about the others because the stdlib type stubs simply alias the types in typing.pyi. From the perspective of Pyright, collections.abc.Iterable is simply an alias for typing.Iterable, so it can't differentiate between the two. If you would like to submit changes to typeshed's stubs so these become distinct types, I could easily add support.

The fix for collections.defaultdict will be in the next release.

@erictraut erictraut added enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Feb 28, 2021
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.3.0, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202130-3-march-2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants