-
-
Notifications
You must be signed in to change notification settings - Fork 3k
mypyc-related stubtest crash #15923
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
Comments
I can reproduce this crash locally on Python 3.9 and Python 3.10, but not Python 3.11 |
And, as @srittau says, the crash only occurs with a compiled version of mypy, which makes it tricky to debug! |
Looks like the TypeError is raised when mypy is trying to validate the default value typeshed gives for one of the parameters in this |
I confirmed locally that applying this diff to typeshed's stubs makes the crash go away: --- a/stubs/fpdf2/fpdf/encryption.pyi
+++ b/stubs/fpdf2/fpdf/encryption.pyi
@@ -65,15 +65,6 @@ class StandardSecurityHandler:
k: str
u: str
- def __init__(
- self,
- fpdf: FPDF,
- owner_password: str,
- user_password: str | None = None,
- permission: Incomplete | None = None,
- encryption_method: EncryptionMethod | None = None,
- encrypt_metadata: bool = False,
- ) -> None: ...
def generate_passwords(self, file_id) -> None: ...
def get_encryption_obj(self) -> EncryptionDictionary: ...
def encrypt(self, text: str | bytes | bytearray, obj_id) -> bytes: ... |
The issue is this call here: Line 1563 in 7141d6b
When attempting to validate the Lines 2560 to 2578 in 7141d6b
Inserting a --- a/mypy/stubtest.py
+++ b/mypy/stubtest.py
@@ -1560,6 +1560,7 @@ def get_mypy_type_of_runtime_value(runtime: Any) -> mypy.types.Type | None:
else:
return fallback
+ reveal_type(value)
return mypy.types.LiteralType(value=value, fallback=fallback)
|
Here is the reason why stubtest crashes on Python <=3.10 but not on Python 3.11. On Python 3.10: Python 3.10.12 | packaged by Anaconda, Inc. | (main, Jul 5 2023, 19:01:18) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fpdf.encryption
>>> fpdf.encryption.AccessPermission.all().name is None
True On Python 3.11: Python 3.11.4 | packaged by Anaconda, Inc. | (main, Jul 5 2023, 13:47:18) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fpdf.encryption
>>> fpdf.encryption.AccessPermission.all().name
'PRINT_LOW_RES|MODIFY|COPY|ANNOTATION|FILL_FORMS|COPY_FOR_ACCESSIBILITY|ASSEMBLE|PRINT_HIGH_RES'
Lines 1556 to 1557 in 7141d6b
But on Python <=3.10, The |
The reason why mypy doesn't pick up that |
I proposed a fix in #15933. The fix is a one-line change, though finding a way to reproduce the crash in the context of stubtest's test suite was a slight challenge 😄 |
Fix edge-case stubtest crashes when an instance of an enum.Flag that is not a member of that enum.Flag is used as a parameter default Fixes #15923. Note: the test cases I've added reproduce the crash, but only if you're using a compiled version of mypy. (Some of them only repro the crash on <=py310, but some repro it on py311+ as well.) We run stubtest tests in CI with compiled mypy, so they do repro the crash in the context of our CI.
Bug Report
In typeshed CI stubtest crashes when run against fpdf2 2.7.5 and the current typeshed stubs. It works fine with fpdf2 2.7.4. Please see python/typeshed#10533, or to be more specific the traceback at https://github.com/python/typeshed/actions/runs/5930009431/job/16078844153?pr=10533:
This error seems to be generated by mypyc. I can't reproduce it locally, possibly because mypyc is not used?
Your Environment
The text was updated successfully, but these errors were encountered: