-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Decouple collections.abc types from typing aliases #6257
Comments
I'm fine with everything that brings typeshed closer to the implementation. But please note that generics are expected to work with |
Good point! The idea originally was to use the old aliases for -- It's easy enough to change, but this will likely cause even more issues as Not quite sure how this can resolve if at all possible. Line 714 in e3180cd
|
This is tricky and I think we'll need some special casing in type checkers either way. On the one hand, we want these types to be treated the same by the type checker for the most part: you should be able to pass a |
If we want type checkers to treat these specially, we may want to define them using |
I've opened #6262 to have some basis for a discussion. |
For pyright, the change is relatively simple (just updating some internal tables). Do you have a full list of affected symbols? Is it simply the subset of symbols listed in PEP 585 that begin with |
Not quite. If I didn't miss any, these should be it.
If I didn't mention a Python version explicitly, it should be supported in |
I just realized that my comment about the Python version can be a bit confusing and not really relevant to the issue. They are the versions where the classes became first available at runtime. What's important
|
I'm having some issues implementing the required mypy changes. The easy part is updating the type alias list here: mypy/nodes.py. The problem I've now come up against is that both The two main areas of conflict:
Maybe someone has an idea, how to resolve it. --
type_aliases: Final = {
...
'typing.Sequence': 'collections.abc.Sequence',
}
type_aliases_source_versions: Final = {
...
'typing.Sequence': (3, 3),
}
from collections.abc import Sequence
def func(var: Sequence[str] = ("Hello",)) -> None:
pass
-- ../typeshed/stdlib/collections/__init__.pyi: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.920+dev.2db0511451ecf511f00dbfc7515cb6fc0d25119c.dirty
Traceback (most recent call last):
...
File "/.../mypy/mypy/__main__.py", line 23, in <module>
console_entry()
File "/.../mypy/mypy/__main__.py", line 11, in console_entry
main(None, sys.stdout, sys.stderr)
File "/.../mypy/mypy/main.py", line 87, in main
res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
File "/.../mypy/mypy/main.py", line 165, in run_build
res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
File "/.../mypy/mypy/build.py", line 180, in build
result = _build(
File "/.../mypy/mypy/build.py", line 256, in _build
graph = dispatch(sources, manager, stdout)
File "/.../mypy/mypy/build.py", line 2712, in dispatch
process_graph(graph, manager)
File "/.../mypy/mypy/build.py", line 3043, in process_graph
process_stale_scc(graph, scc, manager)
File "/.../mypy/mypy/build.py", line 3135, in process_stale_scc
mypy.semanal_main.semantic_analysis_for_scc(graph, scc, manager.errors)
File "/.../mypy/mypy/semanal_main.py", line 78, in semantic_analysis_for_scc
process_top_levels(graph, scc, patches)
File "/.../mypy/mypy/semanal_main.py", line 199, in process_top_levels
deferred, incomplete, progress = semantic_analyze_target(next_id, state,
File "/.../mypy/mypy/semanal_main.py", line 321, in semantic_analyze_target
with state.wrap_context(check_blockers=False):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py", line 153, in __exit__
self.gen.throw(typ, value, traceback)
File "/.../mypy/mypy/build.py", line 1964, in wrap_context
yield
File "/.../mypy/mypy/semanal_main.py", line 326, in semantic_analyze_target
analyzer.refresh_partial(refresh_node,
File "/.../mypy/mypy/semanal.py", line 402, in refresh_partial
self.refresh_top_level(node)
File "/.../mypy/mypy/semanal.py", line 411, in refresh_top_level
self.add_implicit_module_attrs(file_node)
File "/.../mypy/mypy/semanal.py", line 439, in add_implicit_module_attrs
assert isinstance(node, TypeInfo)
AssertionError:
../typeshed/stdlib/collections/__init__.pyi: : note: use --pdb to drop into pdb |
Would proxy types help this at all? |
The error moved to The values in A lot of noise in mypy_primer though, so something's not right. |
At the moment,
collections.abc
types are strict aliases for their typing counterparts. This can make it difficult for intellisense providers to distinguish them and suggest the correct one. @erictraut mentioned that forpyright
: microsoft/pylance-release#1001 (comment).Although this would likely be a lot of code duplication in the short term, I propose to copy the type definitions to the
_collections_abc.pyi
module guarded bysys.version_info >= (3, 9)
.The text was updated successfully, but these errors were encountered: