Open m-legrand opened 3 weeks ago
In all transparency, this might be purely a PyCharm problem and that there is nothing Polars can do. But it's an IDE that is used so widely (in particular in the professional world, with PyCharm Professional for Windows) that it's worth investigating IMHO.
I've also raised this issue (and another similar one concerning arithmetic calculations on pl.Series
) directly to PyCharm in parallel: https://youtrack.jetbrains.com/issue/PY-73306/Type-hints-fail-for-decorated-functions
Hi, just as an update the main issue raised here was a problem with PyCharm, and is solved in their latest build. The other issue is still present, but I suspect this is also a problem on their end.
series = pl.Series(values=[1, 2, 3])
(series - series.mean()).sum() # tooltip saying: Unresolved attribute reference 'sum' for class 'Decimal'
I'll try to get to the bottom of this with them and will close this issue myself if and when this is solved by their team.
Checks
Reproducible example
Log output
No response
Issue description
Using the latest versions of polars, I noticed more and more type hint warnings, leading me to sprinkle my codebase with
# noqa
's... which I would like to avoid. It seems to come from decorated functions, in particular the ones deprecated for deprecation. Indeed, the function returned by the decorator always has a signature with only one parameter calledP
, which is in general different from the original function signature.Screenshots from PyCharm below:
Expected behavior
The functions shouldn't raise type warnings in PyCharm. A function decorated for deprecation should have the same signature as the same function non-decorated (maybe except for the deprecated parameters..?).
Searching the web for such problems I found the
decohints
package trying to solve this issue, maybe copying their approach would work..?Side Note
I wonder if it is possible to mimic the standard library modus operandum, at least for deprecated functions in Polars. The hints for these deprecations are very explicit, screenshot & implementation below: ![image](https://github.com/pola-rs/polars/assets/9072763/c2bbe78e-8078-4b23-b42a-9a8d8d7cc965) ```python @classmethod def utcnow(cls): "Construct a UTC datetime from time.time()." import warnings warnings.warn("datetime.datetime.utcnow() is deprecated and scheduled for " "removal in a future version. Use timezone-aware " "objects to represent datetimes in UTC: " "datetime.datetime.now(datetime.UTC).", DeprecationWarning, stacklevel=2) t = _time.time() return cls._fromtimestamp(t, True, None) ```Installed versions