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 pylint-dev#3826
This adds an unspecified-encoding checker that adds a warning whenever open() is called without an explicit encoding argument. This closes pylint-dev#3826
- Loading branch information
1 parent
e04de25
commit dbb9ccb
Showing
6 changed files
with
121 additions
and
2 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,55 @@ | ||
"""Warnings for using open() without specifying an encoding""" | ||
# pylint: disable=consider-using-with | ||
import io | ||
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 | ||
|
||
io.open(FILENAME, "w+b") | ||
io.open_code(FILENAME) | ||
io.open(FILENAME) # [unspecified-encoding] | ||
io.open(FILENAME, "wt") # [unspecified-encoding] | ||
io.open(FILENAME, "w+") # [unspecified-encoding] | ||
io.open(FILENAME, "w", encoding=None) # [unspecified-encoding] | ||
|
||
with io.open(FILENAME, encoding="utf8", errors="surrogateescape") as f: | ||
pass | ||
|
||
LOCALE_ENCODING = locale.getlocale()[1] | ||
with io.open(FILENAME, encoding=LOCALE_ENCODING) as f: | ||
pass | ||
|
||
with io.open(FILENAME) as f: # [unspecified-encoding] | ||
pass | ||
|
||
with io.open(FILENAME, encoding=None) as f: # [unspecified-encoding] | ||
pass | ||
|
||
LOCALE_ENCODING = None | ||
with io.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,15 @@ | ||
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:14:0::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:23:5::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:26:5::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:30:5::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:35:0::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:36:0::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:37:0::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:38:0::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:47:5::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:50:5::"Using open without explicitly specifying an encoding" | ||
unspecified-encoding:54:5::"Using open without explicitly specifying an encoding" |