|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING, NamedTuple |
| 4 | + |
| 5 | +if TYPE_CHECKING: |
| 6 | + # Import is only needed for type annotations, |
| 7 | + # and causes a circular import if it's imported at runtime. |
| 8 | + from .checker import PyiTreeChecker |
| 9 | + |
| 10 | + |
| 11 | +class Error(NamedTuple): |
| 12 | + lineno: int |
| 13 | + col: int |
| 14 | + message: str |
| 15 | + type: type[PyiTreeChecker] |
| 16 | + |
| 17 | + |
| 18 | +# Please keep error code lists in ERRORCODES and CHANGELOG up to date |
| 19 | +Y001 = "Y001 Name of private {} must start with _" |
| 20 | +Y002 = ( |
| 21 | + "Y002 If test must be a simple comparison against sys.platform or sys.version_info" |
| 22 | +) |
| 23 | +Y003 = "Y003 Unrecognized sys.version_info check" |
| 24 | +Y004 = "Y004 Version comparison must use only major and minor version" |
| 25 | +Y005 = "Y005 Version comparison must be against a length-{n} tuple" |
| 26 | +Y006 = "Y006 Use only < and >= for version comparisons" |
| 27 | +Y007 = "Y007 Unrecognized sys.platform check" |
| 28 | +Y008 = 'Y008 Unrecognized platform "{platform}"' |
| 29 | +Y009 = 'Y009 Empty body should contain "...", not "pass"' |
| 30 | +Y010 = 'Y010 Function body must contain only "..."' |
| 31 | +Y011 = "Y011 Only simple default values allowed for typed arguments" |
| 32 | +Y012 = 'Y012 Class body must not contain "pass"' |
| 33 | +Y013 = 'Y013 Non-empty class body must not contain "..."' |
| 34 | +Y014 = "Y014 Only simple default values allowed for arguments" |
| 35 | +Y015 = "Y015 Only simple default values are allowed for assignments" |
| 36 | +Y016 = 'Y016 Duplicate union member "{}"' |
| 37 | +Y017 = "Y017 Only simple assignments allowed" |
| 38 | +Y018 = 'Y018 {typevarlike_cls} "{typevar_name}" is not used' |
| 39 | +Y019 = ( |
| 40 | + 'Y019 Use "typing_extensions.Self" instead of "{typevar_name}", e.g. "{new_syntax}"' |
| 41 | +) |
| 42 | +Y020 = "Y020 Quoted annotations should never be used in stubs" |
| 43 | +Y021 = "Y021 Docstrings should not be included in stubs" |
| 44 | +Y022 = "Y022 Use {good_syntax} instead of {bad_syntax} (PEP 585 syntax)" |
| 45 | +Y023 = "Y023 Use {good_syntax} instead of {bad_syntax}" |
| 46 | +Y024 = 'Y024 Use "typing.NamedTuple" instead of "collections.namedtuple"' |
| 47 | +Y025 = ( |
| 48 | + 'Y025 Use "from collections.abc import Set as AbstractSet" ' |
| 49 | + 'to avoid confusion with "builtins.set"' |
| 50 | +) |
| 51 | +Y026 = 'Y026 Use typing_extensions.TypeAlias for type aliases, e.g. "{suggestion}"' |
| 52 | +Y028 = "Y028 Use class-based syntax for NamedTuples" |
| 53 | +Y029 = "Y029 Defining __repr__ or __str__ in a stub is almost always redundant" |
| 54 | +Y030 = "Y030 Multiple Literal members in a union. {suggestion}" |
| 55 | +Y031 = "Y031 Use class-based syntax for TypedDicts where possible" |
| 56 | +Y032 = ( |
| 57 | + 'Y032 Prefer "object" to "Any" for the second parameter in "{method_name}" methods' |
| 58 | +) |
| 59 | +Y033 = ( |
| 60 | + "Y033 Do not use type comments in stubs " |
| 61 | + '(e.g. use "x: int" instead of "x = ... # type: int")' |
| 62 | +) |
| 63 | +Y034 = ( |
| 64 | + 'Y034 {methods} usually return "self" at runtime. ' |
| 65 | + 'Consider using "typing_extensions.Self" in "{method_name}", ' |
| 66 | + 'e.g. "{suggested_syntax}"' |
| 67 | +) |
| 68 | +Y035 = ( |
| 69 | + 'Y035 "{var}" in a stub file must have a value, ' |
| 70 | + 'as it has the same semantics as "{var}" at runtime.' |
| 71 | +) |
| 72 | +Y036 = "Y036 Badly defined {method_name} method: {details}" |
| 73 | +Y037 = "Y037 Use PEP 604 union types instead of {old_syntax} (e.g. {example})." |
| 74 | +Y038 = ( |
| 75 | + 'Y038 Use "from collections.abc import Set as AbstractSet" ' |
| 76 | + 'instead of "from {module} import AbstractSet" (PEP 585 syntax)' |
| 77 | +) |
| 78 | +Y039 = 'Y039 Use "str" instead of "{module}.Text"' |
| 79 | +Y040 = 'Y040 Do not inherit from "object" explicitly, as it is redundant in Python 3' |
| 80 | +Y041 = ( |
| 81 | + 'Y041 Use "{implicit_supertype}" ' |
| 82 | + 'instead of "{implicit_subtype} | {implicit_supertype}" ' |
| 83 | + '(see "The numeric tower" in PEP 484)' |
| 84 | +) |
| 85 | +Y042 = "Y042 Type aliases should use the CamelCase naming convention" |
| 86 | +Y043 = 'Y043 Bad name for a type alias (the "T" suffix implies a TypeVar)' |
| 87 | +Y044 = 'Y044 "from __future__ import annotations" has no effect in stub files.' |
| 88 | +Y045 = 'Y045 "{iter_method}" methods should return an {good_cls}, not an {bad_cls}' |
| 89 | +Y046 = 'Y046 Protocol "{protocol_name}" is not used' |
| 90 | +Y047 = 'Y047 Type alias "{alias_name}" is not used' |
| 91 | +Y048 = "Y048 Function body should contain exactly one statement" |
| 92 | +Y049 = 'Y049 TypedDict "{typeddict_name}" is not used' |
| 93 | +Y050 = ( |
| 94 | + 'Y050 Use "typing_extensions.Never" instead of "NoReturn" for argument annotations' |
| 95 | +) |
| 96 | +Y051 = 'Y051 "{literal_subtype}" is redundant in a union with "{builtin_supertype}"' |
| 97 | +Y052 = 'Y052 Need type annotation for "{variable}"' |
| 98 | +Y053 = "Y053 String and bytes literals >50 characters long are not permitted" |
| 99 | +Y054 = ( |
| 100 | + "Y054 Numeric literals with a string representation " |
| 101 | + ">10 characters long are not permitted" |
| 102 | +) |
| 103 | +Y055 = 'Y055 Multiple "type[Foo]" members in a union. {suggestion}' |
| 104 | +Y056 = ( |
| 105 | + 'Y056 Calling "{method}" on "__all__" may not be supported by all type checkers ' |
| 106 | + "(use += instead)" |
| 107 | +) |
| 108 | +Y057 = ( |
| 109 | + "Y057 Do not use {module}.ByteString, which has unclear semantics and is deprecated" |
| 110 | +) |
| 111 | +Y058 = ( |
| 112 | + 'Y058 Use "{good_cls}" as the return value for simple "{iter_method}" methods, ' |
| 113 | + 'e.g. "{example}"' |
| 114 | +) |
| 115 | +Y059 = 'Y059 "Generic[]" should always be the last base class' |
| 116 | +Y060 = ( |
| 117 | + 'Y060 Redundant inheritance from "{redundant_base}"; ' |
| 118 | + "class would be inferred as generic anyway" |
| 119 | +) |
| 120 | +Y061 = 'Y061 None inside "Literal[]" expression. Replace with "{suggestion}"' |
| 121 | +Y062 = 'Y062 Duplicate "Literal[]" member "{}"' |
| 122 | +Y063 = "Y063 Use PEP-570 syntax to indicate positional-only arguments" |
| 123 | +Y064 = 'Y064 Use "{suggestion}" instead of "{original}"' |
| 124 | +Y065 = 'Y065 Leave {what} unannotated rather than using "Incomplete"' |
| 125 | +Y066 = ( |
| 126 | + "Y066 When using if/else with sys.version_info, " |
| 127 | + 'put the code for new Python versions first, e.g. "{new_syntax}"' |
| 128 | +) |
| 129 | +Y067 = 'Y067 Use "=None" instead of "Incomplete | None = None"' |
| 130 | +Y090 = ( |
| 131 | + 'Y090 "{original}" means ' |
| 132 | + '"a tuple of length 1, in which the sole element is of type {typ!r}". ' |
| 133 | + 'Perhaps you meant "{new}"?' |
| 134 | +) |
| 135 | +Y091 = ( |
| 136 | + 'Y091 Argument "{arg}" to protocol method "{method}" should probably not be positional-or-keyword. ' |
| 137 | + "Make it positional-only, since usually you don't want to mandate a specific argument name" |
| 138 | +) |
| 139 | + |
| 140 | +DISABLED_BY_DEFAULT = ["Y090", "Y091"] |
0 commit comments