forked from pylint-dev/pylint
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unspecified-encoding checker PyCQA#3826
This adds an unspecified-encoding checker that adds a warning whenever open() is called without an explicit encoding argument. This closes PyCQA#3826
- Loading branch information
1 parent
e04de25
commit ed6aca8
Showing
6 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Warnings for using open() without specifying an encoding""" | ||
# pylint: disable=consider-using-with | ||
import locale | ||
|
||
FILENAME = "foo.bar" | ||
open(FILENAME, "w", encoding="utf-8") | ||
open(FILENAME, "wb") | ||
open(FILENAME, "w+b") | ||
open(FILENAME) # [unspecified-encoding] | ||
open(FILENAME, "wt") # [unspecified-encoding] | ||
open(FILENAME, "w+") # [unspecified-encoding] | ||
open(FILENAME, "w", encoding=None) # [unspecified-encoding] | ||
open(FILENAME, "r") # [unspecified-encoding] | ||
|
||
with open(FILENAME, encoding="utf8", errors="surrogateescape") as f: | ||
pass | ||
|
||
LOCALE_ENCODING = locale.getlocale()[1] | ||
with open(FILENAME, encoding=LOCALE_ENCODING) as f: | ||
pass | ||
|
||
with open(FILENAME) as f: # [unspecified-encoding] | ||
pass | ||
|
||
with open(FILENAME, encoding=None) as f: # [unspecified-encoding] | ||
pass | ||
|
||
LOCALE_ENCODING = None | ||
with open(FILENAME, encoding=LOCALE_ENCODING) as f: # [unspecified-encoding] | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
unspecified-encoding:9:0::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:10:0::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:11:0::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:12:0::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:13:0::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:22:5::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:25:5::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:29:5::"Using open without explicitly specifying an encoding" |