ruff/crates/red_knot_python_semantic/src
Carl Meyer a6d3d2fccd
[red-knot] support reveal_type as pseudo-builtin (#13403)
Support using `reveal_type` without importing it, as implied by the type
spec and supported by existing type checkers.

We use `typing_extensions.reveal_type` for the implicit built-in; this
way it exists on all Python versions. (It imports from `typing` on newer
Python versions.)

Emits an "undefined name" diagnostic whenever `reveal_type` is
referenced in this way (in addition to the revealed-type diagnostic when
it is called). This follows the mypy example (with `--enable-error-code
unimported-reveal`) and I think provides a good (and easily
understandable) balance for user experience. If you are using
`reveal_type` for quick temporary debugging, the additional
undefined-name diagnostic doesn't hinder that use case. If we make the
revealed-type diagnostic a non-failing one, the undefined-name
diagnostic can still be a failing diagnostic, helping prevent
accidentally leaving it in place. For any use cases where you want to
leave it in place, you can always import it to avoid the undefined-name
diagnostic.

In the future, we can easily provide configuration options to a) turn
off builtin-reveal_type altogether, and/or b) silence the undefined-name
diagnostic when using it, if we have users on either side (loving or
hating pseudo-builtin `reveal_type`) who are dissatisfied with this
compromise.
2024-09-19 07:58:08 -07:00
..
module_resolver [red-knot] resolve source/stubs over namespace packages (#13254) 2024-09-06 12:14:26 +01:00
semantic_index Fix/#13070 defer annotations when future is active (#13395) 2024-09-19 10:13:37 +02:00
types [red-knot] support reveal_type as pseudo-builtin (#13403) 2024-09-19 07:58:08 -07:00
ast_node_ref.rs Add definitions for match statement (#13147) 2024-09-02 14:40:09 +05:30
db.rs Add API to emit type-checking diagnostics (#12988) 2024-08-20 07:22:30 +00:00
lib.rs [red-knot] use declared types in inference/checking (#13335) 2024-09-17 08:11:06 -07:00
module_name.rs [red-knot] Add support for relative imports (#12910) 2024-08-16 12:35:27 +01:00
node_key.rs Implement AstNode for Identifier (#13207) 2024-09-02 16:27:12 +05:30
program.rs Eagerly validate typeshed versions (#12786) 2024-08-21 15:49:53 +00:00
python_version.rs Remove red_knot_python_semantic::python_version::TargetVersion (#12790) 2024-08-10 14:28:31 +01:00
semantic_index.rs Fix/#13070 defer annotations when future is active (#13395) 2024-09-19 10:13:37 +02:00
semantic_model.rs [red-knot] use declared types in inference/checking (#13335) 2024-09-17 08:11:06 -07:00
site_packages.rs Eagerly validate typeshed versions (#12786) 2024-08-21 15:49:53 +00:00
stdlib.rs [red-knot] support reveal_type as pseudo-builtin (#13403) 2024-09-19 07:58:08 -07:00
types.rs [red-knot] support reveal_type as pseudo-builtin (#13403) 2024-09-19 07:58:08 -07:00