|
| 1 | +--- |
| 2 | +source: crates/ty_test/src/lib.rs |
| 3 | +expression: snapshot |
| 4 | +--- |
| 5 | +--- |
| 6 | +mdtest name: special_form_attributes.md - Diagnostics for invalid attribute access on special forms |
| 7 | +mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/special_form_attributes.md |
| 8 | +--- |
| 9 | + |
| 10 | +# Python source files |
| 11 | + |
| 12 | +## mdtest_snippet.py |
| 13 | + |
| 14 | +``` |
| 15 | + 1 | from typing_extensions import Any, Final, LiteralString, Self |
| 16 | + 2 | |
| 17 | + 3 | X = Any |
| 18 | + 4 | |
| 19 | + 5 | class Foo: |
| 20 | + 6 | X: Final = LiteralString |
| 21 | + 7 | a: int |
| 22 | + 8 | b: Self |
| 23 | + 9 | |
| 24 | +10 | class Bar: |
| 25 | +11 | def __init__(self): |
| 26 | +12 | self.y: Final = LiteralString |
| 27 | +13 | |
| 28 | +14 | X.foo # error: [unresolved-attribute] |
| 29 | +15 | X.aaaaooooooo # error: [unresolved-attribute] |
| 30 | +16 | Foo.X.startswith # error: [unresolved-attribute] |
| 31 | +17 | Foo.Bar().y.startswith # error: [unresolved-attribute] |
| 32 | +18 | |
| 33 | +19 | # TODO: false positive (just testing the diagnostic in the meantime) |
| 34 | +20 | Foo().b.a # error: [unresolved-attribute] |
| 35 | +``` |
| 36 | + |
| 37 | +# Diagnostics |
| 38 | + |
| 39 | +``` |
| 40 | +error[unresolved-attribute]: Special form `typing.Any` has no attribute `foo` |
| 41 | + --> src/mdtest_snippet.py:14:1 |
| 42 | + | |
| 43 | +12 | self.y: Final = LiteralString |
| 44 | +13 | |
| 45 | +14 | X.foo # error: [unresolved-attribute] |
| 46 | + | ^^^^^ |
| 47 | +15 | X.aaaaooooooo # error: [unresolved-attribute] |
| 48 | +16 | Foo.X.startswith # error: [unresolved-attribute] |
| 49 | + | |
| 50 | +help: Objects with type `Any` have a `foo` attribute, but the symbol `typing.Any` does not itself inhabit the type `Any` |
| 51 | +help: This error may indicate that `X` was defined as `X = typing.Any` when `X: typing.Any` was intended |
| 52 | +info: rule `unresolved-attribute` is enabled by default |
| 53 | +
|
| 54 | +``` |
| 55 | + |
| 56 | +``` |
| 57 | +error[unresolved-attribute]: Special form `typing.Any` has no attribute `aaaaooooooo` |
| 58 | + --> src/mdtest_snippet.py:15:1 |
| 59 | + | |
| 60 | +14 | X.foo # error: [unresolved-attribute] |
| 61 | +15 | X.aaaaooooooo # error: [unresolved-attribute] |
| 62 | + | ^^^^^^^^^^^^^ |
| 63 | +16 | Foo.X.startswith # error: [unresolved-attribute] |
| 64 | +17 | Foo.Bar().y.startswith # error: [unresolved-attribute] |
| 65 | + | |
| 66 | +help: Objects with type `Any` have an `aaaaooooooo` attribute, but the symbol `typing.Any` does not itself inhabit the type `Any` |
| 67 | +help: This error may indicate that `X` was defined as `X = typing.Any` when `X: typing.Any` was intended |
| 68 | +info: rule `unresolved-attribute` is enabled by default |
| 69 | +
|
| 70 | +``` |
| 71 | + |
| 72 | +``` |
| 73 | +error[unresolved-attribute]: Special form `typing.LiteralString` has no attribute `startswith` |
| 74 | + --> src/mdtest_snippet.py:16:1 |
| 75 | + | |
| 76 | +14 | X.foo # error: [unresolved-attribute] |
| 77 | +15 | X.aaaaooooooo # error: [unresolved-attribute] |
| 78 | +16 | Foo.X.startswith # error: [unresolved-attribute] |
| 79 | + | ^^^^^^^^^^^^^^^^ |
| 80 | +17 | Foo.Bar().y.startswith # error: [unresolved-attribute] |
| 81 | + | |
| 82 | +help: Objects with type `LiteralString` have a `startswith` attribute, but the symbol `typing.LiteralString` does not itself inhabit the type `LiteralString` |
| 83 | +help: This error may indicate that `Foo.X` was defined as `Foo.X = typing.LiteralString` when `Foo.X: typing.LiteralString` was intended |
| 84 | +info: rule `unresolved-attribute` is enabled by default |
| 85 | +
|
| 86 | +``` |
| 87 | + |
| 88 | +``` |
| 89 | +error[unresolved-attribute]: Special form `typing.LiteralString` has no attribute `startswith` |
| 90 | + --> src/mdtest_snippet.py:17:1 |
| 91 | + | |
| 92 | +15 | X.aaaaooooooo # error: [unresolved-attribute] |
| 93 | +16 | Foo.X.startswith # error: [unresolved-attribute] |
| 94 | +17 | Foo.Bar().y.startswith # error: [unresolved-attribute] |
| 95 | + | ^^^^^^^^^^^^^^^^^^^^^^ |
| 96 | +18 | |
| 97 | +19 | # TODO: false positive (just testing the diagnostic in the meantime) |
| 98 | + | |
| 99 | +help: Objects with type `LiteralString` have a `startswith` attribute, but the symbol `typing.LiteralString` does not itself inhabit the type `LiteralString` |
| 100 | +info: rule `unresolved-attribute` is enabled by default |
| 101 | +
|
| 102 | +``` |
| 103 | + |
| 104 | +``` |
| 105 | +error[unresolved-attribute]: Special form `typing.Self` has no attribute `a` |
| 106 | + --> src/mdtest_snippet.py:20:1 |
| 107 | + | |
| 108 | +19 | # TODO: false positive (just testing the diagnostic in the meantime) |
| 109 | +20 | Foo().b.a # error: [unresolved-attribute] |
| 110 | + | ^^^^^^^^^ |
| 111 | + | |
| 112 | +info: rule `unresolved-attribute` is enabled by default |
| 113 | +
|
| 114 | +``` |
0 commit comments