void (@NotNull PyStringLiteralExpression node) { String value = node.getStringValue(); PsiFile file = node.getContainingFile(); // can't cache this in the instance, alas if (file == null) return; boolean default_bytes = false; if (file instanceof PyFile pyfile) { default_bytes = (!UNICODE_LITERALS.requiredAt(pyfile.getLanguageLevel()) && !pyfile.hasImportFromFuture(UNICODE_LITERALS) ); } final String charsetString = PythonFileType.getCharsetFromEncodingDeclaration(file); try { if (charsetString != null && !Charset.forName(charsetString).equals(StandardCharsets.US_ASCII)) default_bytes = false; } catch (UnsupportedCharsetException | IllegalCharsetNameException ignored) {} boolean hasNonAscii = false; int length = value.length(); char c = 0; for (int i = 0; i < length; ++i) { c = value.charAt(i); if (((int) c) > 255) { hasNonAscii = true; break; } } char first_char = Character.toLowerCase(node.getText().charAt(0)); boolean isByte = first_char == 'b' || (default_bytes && first_char != 'u'); if (hasNonAscii && isByte) { registerProblem(node, PyPsiBundle.message("INSP.byte.literal.contains.illegal.characters")); } }