reloadware/reloadium

python 3.11 annotations unsupported.

Closed this issue · 11 comments

Describe the bug*

I am constantly getting errors due to static typing

This seems to be an issue with python 3.11-style annotations. I'm using python 3.12 3.8.10 yet it's still giving me errors due to annotation style. Anytime I save. It's quite obnoxious and it doesn't seem to be possible in the settings to disable.

Update Module: toolset.gui.windows.module_designer
Oops, it seems like you made a mistake.
Fix your changes and save to reload.

To Reproduce

Steps to reproduce the behavior:

  1. Start a reloadium debug/fastdebug/run/whatever
  2. Save any python file using python 3.11 annotations
  3. Work on some code for more than 5 seconds in the same file
  4. Be interrupted abruptly due to reloadium saying 'whoops! there's an error! please fix your code'

Expected behavior

Actual parsing of python 3.11 annotations. At the very least, a way to disable it's error check routine.

Screenshots

image
image

Desktop or remote (please complete the following information):**

  • OS: Windows 10
  • OS version: latest update as of 2/28/2014
  • M1 chip: No idea
  • Reloadium package version: latest update as of 2/28/2014
  • PyCharm plugin version: latest update as of 2/28/2014
  • Editor: PyCharm
  • Python Version: 3.12.2 3.8.10
  • Python Architecture: 64bit
  • Run mode: Literally all of them.

Additional Context:

I remember experiencing this a few times unrelated to this plugin when I've used older versions of python and forgot to import from __future__ import annotations. The error messages reloadium is giving me look quite similar to that scenario.

Are you sure you're running it under 3.12? 3.12 is not supported yet.

Whoops, sorry I'm a bit new to pycharm. Looks like I'm running python 3.8 with from __future__ import annotations at the top of my script

Have been googling for the last hour and haven't found anyone else mention this problem or how to resolve it, any tips?

Correct usage would be:

from typing import Set
buttons: Set[int]

I'm closing this since it's not related to Reloadium

In my opinion this is definitely a bug. I'm using a supported version of python (according to your docs) and I'm getting undesirable behavior due to perfectly acceptable python typing. If this doesn't intend to be supported, perhaps it could be documented somewhere at least?

from typing import Set
buttons: Set[int]

You've shown an example of the old-style annotations,

The annotation style (lowercase set) is perfectly acceptable in python 3.8 if you import from __future__ import annotations at the top of your script.

To add, we have a library of hundreds of python scripts using the future annotation syntax. To my knowledge I don't believe there's a tool that'll auto downgrade to the old style. I know tools like Ruff and pyupgrade will automatically convert to future annotations however.

I see what you mean but I can't reproduce it.

2024-02-28_23:33:44

Can you provide a reproducer?

I was struggling to get consistent results, as there didn't seem to be a command to get Reloadium to simply just try to parse a single file. After a bit of experimentation, I finally was able to get it to throw an error in a script consistently, without any non-builtin dependencies.

https://github.com/NickHugi/PyKotor/blob/master/Libraries/Utility/src/utility/system/path.py

image

From what I gather your parser needs to be doing two things:

It might be easier to import something like ruff/pylint to do quick checks like this. Another potential idea is to expose a checkbox in the settings to disable Reloadium's syntax checks. In my scenario, the only thing I want Reloadium to do is reload the changed code/affected modules: I couldn't care less about whether it finds an error in the code.

In the above example, I have the following import structure, compliant with PEP 563

from __future__ import annotations

import contextlib
import os
import pathlib
import re
import subprocess
import sys
import uuid

from tempfile import TemporaryDirectory
from typing import TYPE_CHECKING, Any, Union

from utility.error_handling import format_exception_with_variables

if TYPE_CHECKING:
    from collections.abc import Callable, Generator

    from typing_extensions import Self

I still can't reproduce it but you're right, there is some custom logic around parsing future imports.
I'll have a look into that.

Fixed in Reloadium 1.4.1 and PyCharm plugin 1.4.1