Skip to content

Add @final to slice/memoryview/range #6289

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

Merged
merged 3 commits into from
Nov 14, 2021
Merged

Conversation

AlexWaygood
Copy link
Member

None of these classes can be subclassed at runtime.

None of these classes can be subclassed at runtime.
@JelleZijlstra
Copy link
Member

Looks like you found a mypy bug: ast.pyi defines its own class called slice, but somehow it's checking @final on builtins.slice?

@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member Author

Looks like you found a mypy bug: ast.pyi defines its own class called slice, but somehow it's checking @final on builtins.slice?

😣

@hauntsaninja
Copy link
Collaborator

Hmm, the other weird thing is that the mypy tests pass, it's only when running the mypy build in the stubtest invocation does it fail...

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Nov 12, 2021

hmm hmm hmm, locally:

stubtest --custom-typeshed-dir . ast  # passes
stubtest --custom-typeshed-dir . ast _ast  # passes
stubtest --custom-typeshed-dir . _ast ast  # fails

mypy --python-version 3.10 --no-incremental --custom-typeshed-dir . stdlib/ast.pyi stdlib/_ast.pyi  # passes
mypy --python-version 3.10 --no-incremental --custom-typeshed-dir . stdlib/_ast.pyi stdlib/ast.pyi   # fails

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Nov 13, 2021

Spent some more time digging through mypy code, it's pretty thorny.

Here's a one character fix:

diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi
index b4890072..53575f8f 100644
--- a/stdlib/builtins.pyi
+++ b/stdlib/builtins.pyi
@@ -19,7 +19,7 @@ from _typeshed import (
     SupportsRDivMod,
     SupportsWrite,
 )
-from ast import AST, mod
+from _ast import AST, mod
 from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
 from types import CodeType, MappingProxyType, TracebackType
 from typing import (

There's really a lot going on here: 1) collision with a name in builtins, 2) builtins depending on ast, 3) ast doing from _ast import *. This removes point 3 from the equation, which helps.

@AlexWaygood
Copy link
Member Author

Spent some more time digging through mypy code, it's pretty thorny.

Here's a one character fix:
[...]

Amazing, thanks for looking into it! I'll see if I can edit my patch tomorrow.

@JelleZijlstra
Copy link
Member

Thanks for investigating @hauntsaninja!

Not sure if it will make a difference, but it looks like we can also remove mod from that import. It's only used in a union with AST in an argument type, and _ast.mod is a subclass of _ast.AST.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood
Copy link
Member Author

Huzzah!

@JelleZijlstra JelleZijlstra merged commit f6e697f into python:master Nov 14, 2021
@AlexWaygood AlexWaygood deleted the patch-1 branch November 14, 2021 02:05
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

Successfully merging this pull request may close these issues.

3 participants