microsoft / python-type-stubs

A set of type stubs for popular Python packages. These are works in progress from the Microsoft Python team and others, with the intent that they are contributed to typeshed or to the associated packages once sufficiently complete.
MIT License
252 stars 99 forks source link

Unmark `sklearn.metrics.mean_squared_error` and `mean_squared_log_error` as deprecated #319

Closed InSyncWithFoo closed 1 month ago

InSyncWithFoo commented 1 month ago

Instead, two @deprecated overloads were added with helpful messages to specify that only squared is deprecated.

Resolves #318.

debonte commented 1 month ago

@InSyncWithFoo, as far as I can tell, Pylance doesn't have any support for deprecated overloads and PEP 702 explicitly chose to not add a way to deprecate parameters.

I'm not sure the added complexity of overloads here is worthwhile. What do you think about just removing the @deprecated decorators?

InSyncWithFoo commented 1 month ago

Pylance doesn't have any support for deprecated overloads [...]

What do you mean? Deprecated overload usages are explicitly specified to be errors and Pyright is able to report them as such (playground):

@deprecated("Foobar")
@overload
def f(v: int, *, b: bool) -> None: ...

@overload
def f(v: int) -> None: ...
f(0, b = False)  # error: The function "f" is deprecated
f(0)             # fine

While it is true that there is no Deprecated[] modifier, this limitation can be overcome by using @overloads, and I don't see any reason not to do so.

debonte commented 1 month ago

Thanks. I'm not sure why I wasn't seeing this work before, but I see the diagnostic hint now.

The error text is a bit misleading since it starts off by saying that the function is deprecated, but as long as they keep reading through the descriptive text you added users should be ok. image

Thanks for the contribution.