microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.72k stars 766 forks source link

pylance is adding () when auto paran is enabled for decorator #4215

Closed heejaechang closed 1 month ago

heejaechang commented 1 year ago

type @override or @overload

in

class A:
       @overload

if autoParan is on, pylance will insert () after decorator interfering typing.

rchiodo commented 1 year ago

Yeah that seems like a case we should skip adding the parens.

StellaHuang95 commented 6 months ago

Briefly looked at this issue, @heejaechang are we suggesting to disable parentheses for all decorators? There're decorators with parameters that would need the parentheses to be there.

heejaechang commented 6 months ago

I think doing less is better than doing wrong. because doing wrong will require users to fix things up. especially if it is done without user explicit asking such as this case.

so in my opinion, the simplest way to fix will be just not adding () for all decorators. but that said, if we want to make it a bit smarter, then we can check whether the decorator is a regular decorator (one that doesn't have arguments), or decorator factory (one that has arguments) and only add () if we are sure the decorator is a decorator factory.

I didn't see the code to see whether there is already existing info on whether decorator is factory or not. but if not, we could use some heuristic to check.

just NOTE, any additional semantic check can impact typing perf. so, we should make sure perf cost is not that high otherwise, I think no feature is worth to sacrificing typing perf.