Skip to content

Conversation

fangyi-zhou
Copy link
Contributor

This diff implements the last missing feature for deprecation warnings (#376): to warn when the deprecated function is referred (e.g. passed as function reference).

The implementation checks when typechecking an expression, whether the type of an expression is a deprecated function/bound method. If that's the case, a deprecated warning is generated.

If we only add this check, we might run into the issue that a deprecated function call would generate 2 deprecation warnings, one when the function is typechecked, and another when the call is typechecked.

To avoid the duplication, we avoid emitting the deprecation warning when typechecking a function call, instead we emit the deprecation warning when generating the call target.

As a consequence, the error message of deprecation warning is changed from "Calling" a deprecated function to "Reference to" a deprecated function. Suggestions are welcome for how to improve clarify of this error message.

This diff implements the last missing feature for deprecation warnings:
to warn when the deprecated function is referred (e.g. passed as
function reference).

The implementation checks when typechecking an expression, whether the
type of an expression is a deprecated function/bound method. If that's
the case, a deprecated warning is generated.

If we only add this check, we might run into the issue that a deprecated
function call would generate 2 deprecation warnings, one when the
function is typechecked, and another when the call is typechecked.

To avoid the duplication, we avoid emitting the deprecation warning when
typechecking a function call, instead we emit the deprecation warning
when generating the call target.

As a consequence, the error message of deprecation warning is changed
from "Calling" a deprecated function to "Reference to" a deprecated
function. Suggestions are welcome for how to improve clarify of this
error message.
@facebook-github-bot
Copy link
Contributor

@yangdanny97 has imported this pull request. If you are a Meta employee, you can view this in D81681196.

@yangdanny97
Copy link
Contributor

Sorry for the delay here,

Maybe {function name} is deprecated for simplicity?

Mypy and Pyright's error messages, for reference:

https://github.com/python/typing/blob/main/conformance/results/pyright/directives_deprecated.toml

https://github.com/python/typing/blob/main/conformance/results/mypy/directives_deprecated.toml

The rest of it LGTM

Copy link
Contributor

@rchen152 rchen152 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@yangdanny97
Copy link
Contributor

@fangyi-zhou I'll patch the error message in the imported version

@facebook-github-bot
Copy link
Contributor

@yangdanny97 merged this pull request in 02f67b8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants