reloadware / reloadium

Hot Reloading and Profiling for Python
https://reloadium.io
Apache License 2.0
2.74k stars 56 forks source link

python 3.11 annotations unsupported. #184

Closed th3w1zard1 closed 2 months ago

th3w1zard1 commented 4 months ago

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):**

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.

dkrystki commented 4 months ago

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

th3w1zard1 commented 4 months ago

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

th3w1zard1 commented 4 months ago

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

dkrystki commented 4 months ago

Correct usage would be:

from typing import Set
buttons: Set[int]

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

th3w1zard1 commented 4 months ago

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.

th3w1zard1 commented 4 months ago

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.

dkrystki commented 4 months ago

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

2024-02-28_23:33:44

Can you provide a reproducer?

th3w1zard1 commented 4 months ago

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.

th3w1zard1 commented 4 months ago

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
dkrystki commented 4 months ago

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.

dkrystki commented 2 months ago

Fixed in Reloadium 1.4.1 and PyCharm plugin 1.4.1