Add mdtest support for files with invalid syntax (#14126)

This commit is contained in:
Micha Reiser 2024-11-06 12:25:52 +01:00 committed by GitHub
parent 4ece8e5c1e
commit a56ee9268e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 137 additions and 70 deletions

View file

@ -0,0 +1,13 @@
# Exception Handling
## Invalid syntax
```py
from typing_extensions import reveal_type
try:
print
except as e: # error: [invalid-syntax]
reveal_type(e) # revealed: Unknown
```

View file

@ -8,7 +8,7 @@ use std::sync::Arc;
use crate::types::{ClassLiteralType, Type};
use crate::Db;
#[derive(Debug, Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq, Clone)]
pub struct TypeCheckDiagnostic {
// TODO: Don't use string keys for rules
pub(super) rule: String,

View file

@ -5061,27 +5061,6 @@ mod tests {
Ok(())
}
#[test]
fn exception_handler_with_invalid_syntax() -> anyhow::Result<()> {
let mut db = setup_db();
db.write_dedented(
"src/a.py",
"
from typing_extensions import reveal_type
try:
print
except as e:
reveal_type(e)
",
)?;
assert_file_diagnostics(&db, "src/a.py", &["Revealed type is `Unknown`"]);
Ok(())
}
#[test]
fn basic_comprehension() -> anyhow::Result<()> {
let mut db = setup_db();
@ -5424,7 +5403,7 @@ mod tests {
return 42
class Iterable:
def __iter__(self) -> Iterator:
def __iter__(self) -> Iterator: ...
x = [*NotIterable()]
y = [*Iterable()]