diff --git a/crates/red_knot_python_semantic/resources/mdtest/attributes.md b/crates/red_knot_python_semantic/resources/mdtest/attributes.md index 868c86b807..63baa047bc 100644 --- a/crates/red_knot_python_semantic/resources/mdtest/attributes.md +++ b/crates/red_knot_python_semantic/resources/mdtest/attributes.md @@ -393,8 +393,6 @@ reveal_type(D().x) # revealed: Unknown | Literal[1] If `staticmethod` is something else, that should not influence the behavior: -`other.py`: - ```py def staticmethod(f): return f @@ -409,8 +407,6 @@ reveal_type(C().x) # revealed: Unknown | Literal[1] And if `staticmethod` is fully qualified, that should also be recognized: -`fully_qualified.py`: - ```py import builtins diff --git a/crates/red_knot_python_semantic/resources/mdtest/statically_known_branches.md b/crates/red_knot_python_semantic/resources/mdtest/statically_known_branches.md index 97dc6873a1..3b99c1a32e 100644 --- a/crates/red_knot_python_semantic/resources/mdtest/statically_known_branches.md +++ b/crates/red_knot_python_semantic/resources/mdtest/statically_known_branches.md @@ -7,43 +7,36 @@ branches whose conditions we can statically determine to be always true or alway useful for `sys.version_info` branches, which can make new features available based on the Python version: -`module1.py`: +If we can statically determine that the condition is always true, then we can also understand that +`SomeFeature` is always bound, without raising any errors: ```py import sys -if sys.version_info >= (3, 9): - SomeFeature: str = "available" -``` +class C: + if sys.version_info >= (3, 9): + SomeFeature: str = "available" -If we can statically determine that the condition is always true, then we can also understand that -`SomeFeature` is always bound, without raising any errors: - -`test1.py`: - -```py -from module1 import SomeFeature - -# SomeFeature is unconditionally available here, because we are on Python 3.9 or newer: -reveal_type(SomeFeature) # revealed: str +# C.SomeFeature is unconditionally available here, because we are on Python 3.9 or newer: +reveal_type(C.SomeFeature) # revealed: str ``` Another scenario where this is useful is for `typing.TYPE_CHECKING` branches, which are often used for conditional imports: -`module2.py`: +`module.py`: ```py class SomeType: ... ``` -`test2.py`: +`main.py`: ```py import typing if typing.TYPE_CHECKING: - from module2 import SomeType + from module import SomeType # `SomeType` is unconditionally available here for type checkers: def f(s: SomeType) -> None: ... diff --git a/crates/red_knot_test/README.md b/crates/red_knot_test/README.md index 34c1264bcc..f802f9ea90 100644 --- a/crates/red_knot_test/README.md +++ b/crates/red_knot_test/README.md @@ -133,7 +133,7 @@ be merged into a single file in the order they appear in the Markdown file. This interleave code and explanations: ````markdown -# My literal test +# My literate test This first snippet here: diff --git a/crates/red_knot_test/src/parser.rs b/crates/red_knot_test/src/parser.rs index 281799b669..8ed9d40d1d 100644 --- a/crates/red_knot_test/src/parser.rs +++ b/crates/red_knot_test/src/parser.rs @@ -274,15 +274,9 @@ impl EmbeddedFile<'_> { self.backtick_offsets.push(backtick_offsets); - match self.code { - Cow::Borrowed(existing_code) => { - self.code = Cow::Owned(format!("{existing_code}\n{new_code}")); - } - Cow::Owned(ref mut existing_code) => { - existing_code.push('\n'); - existing_code.push_str(new_code); - } - } + let existing_code = self.code.to_mut(); + existing_code.push('\n'); + existing_code.push_str(new_code); } pub(crate) fn relative_path(&self) -> &str {