From bc3a735d93304ea7a2f9c336dcfe1d3428a02f09 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sat, 28 Dec 2024 16:47:03 -0800 Subject: [PATCH] Test explicit shadowing involving `def`s (#15174) Co-authored-by: Carl Meyer --- .../resources/mdtest/shadowing/function.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/red_knot_python_semantic/resources/mdtest/shadowing/function.md b/crates/red_knot_python_semantic/resources/mdtest/shadowing/function.md index d7cf209f54..591249dde7 100644 --- a/crates/red_knot_python_semantic/resources/mdtest/shadowing/function.md +++ b/crates/red_knot_python_semantic/resources/mdtest/shadowing/function.md @@ -25,3 +25,29 @@ def f(): ... f: int = 1 ``` + +## Explicit shadowing involving `def` statements + +Since a `def` statement is a declaration, one `def` can shadow another `def`, or shadow a previous +non-`def` declaration, without error. + +```py +f = 1 +reveal_type(f) # revealed: Literal[1] + +def f(): ... + +reveal_type(f) # revealed: Literal[f] + +def f(x: int) -> int: + raise NotImplementedError + +reveal_type(f) # revealed: Literal[f] + +f: int = 1 +reveal_type(f) # revealed: Literal[1] + +def f(): ... + +reveal_type(f) # revealed: Literal[f] +```