Skip to content

Conversation

@practicalswift
Copy link
Contributor

Add linter: Make sure we explicitly open all text files using UTF-8 encoding in Python.

As requested by @laanwj in #13440.

@promag
Copy link
Contributor

promag commented Jun 12, 2018

Concept ACK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you upstream this? (Asking only half-serious)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately LLVM does not use GitHub (beyond a repo mirror) and I try to limit my open source contributions to projects accepting GitHub PR:s due to time constraints :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cookie file is ASCII encoded

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that's a problem: if something is ASCII-encoded, it doesn't hurt reading it as utf-8.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion. Would throw and error if it was no longer ascii.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

txids should only be ascii encoded

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cookie file is ASCII encoded

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should say encoding='utf8'? Also, you might want to use the single quotes(') when patching the python files in this pull, since this seems the more common way for short strings. Just a nit, though.

@maflcko
Copy link
Member

maflcko commented Jun 12, 2018

utACK 743add2f9ee381b80f70869585cd48e89efc5df1. Just a few nits. Feel free to ignore them.

@laanwj
Copy link
Member

laanwj commented Jun 12, 2018

Thanks for adding this.
utACK 743add2f9ee381b80f70869585cd48e89efc5df1, no strong opinion on ascii versus utf-8. I'm ok with being strict there, or keeping it like this, the point is being explicit.

Edit, this trips up the linter in travis:

Python's open(...) seems to be used to open text files without explicitly
specifying 'encoding=utf8':
contrib/verify-commits/verify-commits.py:    verified_root = open(dirname + "/trusted-git-root", "r").read().splitlines()[0]
contrib/verify-commits/verify-commits.py:    verified_sha512_root = open(dirname + "/trusted-sha512-root-commit", "r").read().splitlines()[0]
contrib/verify-commits/verify-commits.py:    revsig_allowed = open(dirname + "/allow-revsig-commits", "r").read().splitlines()
contrib/verify-commits/verify-commits.py:    unclean_merge_allowed = open(dirname + "/allow-unclean-merge-commits", "r").read().splitlines()
contrib/verify-commits/verify-commits.py:    incorrect_sha512_allowed = open(dirname + "/allow-incorrect-sha512-commits", "r").read().splitlines()
^---- failure generated from test/lint/lint-python-utf8-encoding.sh

@practicalswift practicalswift force-pushed the lint-python-utf8-encoding branch 4 times, most recently from 2706dd2 to 3a12a51 Compare June 12, 2018 19:48
@practicalswift practicalswift force-pushed the lint-python-utf8-encoding branch from 3a12a51 to c8176b3 Compare June 12, 2018 19:49
@practicalswift
Copy link
Contributor Author

@MarcoFalke @laanwj Thanks for the quick review. Feedback addressed. Please re-review :-)

@maflcko
Copy link
Member

maflcko commented Jun 12, 2018

utACK c8176b3

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 14, 2018

Note to reviewers: This pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@ken2812221 ken2812221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK c8176b3

# avoid potential issues on the BSDs where the locale is not always set.

EXIT_CODE=0
OUTPUT=$(git grep " open(" -- "*.py" | grep -vE "encoding=.(ascii|utf8|utf-8)." | grep -vE "open\([^,]*, ['\"][^'\"]*b[^'\"]*['\"]")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would prefer not to use . to match "

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It matches also '. Imo every other character would be a syntax error in python, so should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ken2812221 That is intentional to match ' and ".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that makes sense.

@laanwj laanwj merged commit c8176b3 into bitcoin:master Jun 16, 2018
laanwj added a commit that referenced this pull request Jun 16, 2018
… using UTF-8 encoding in Python

c8176b3 Add linter: Make sure we explicitly open all text files using UTF-8 or ASCII encoding in Python (practicalswift)
634bd97 Explicitly specify encoding when opening text files in Python code (practicalswift)

Pull request description:

  Add linter: Make sure we explicitly open all text files using UTF-8 encoding in Python.

  As requested by @laanwj in #13440.

Tree-SHA512: 1651c00fe220ceb273324abd6703aee504029b96c7ef0e3029145901762c733c9b9d24927da281394fd4681a5bff774336c04eed01fafea997bb32192c334c06
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 7, 2020
…t files using UTF-8 encoding in Python

c8176b3 Add linter: Make sure we explicitly open all text files using UTF-8 or ASCII encoding in Python (practicalswift)
634bd97 Explicitly specify encoding when opening text files in Python code (practicalswift)

Pull request description:

  Add linter: Make sure we explicitly open all text files using UTF-8 encoding in Python.

  As requested by @laanwj in bitcoin#13440.

Tree-SHA512: 1651c00fe220ceb273324abd6703aee504029b96c7ef0e3029145901762c733c9b9d24927da281394fd4681a5bff774336c04eed01fafea997bb32192c334c06
Signed-off-by: pasta <[email protected]>

# Conflicts:
#	contrib/devtools/circular-dependencies.py
#	contrib/linearize/linearize-data.py
#	contrib/linearize/linearize-hashes.py
#	contrib/seeds/generate-seeds.py
#	contrib/verify-commits/verify-commits.py
#	test/functional/multiwallet.py
#	test/functional/notifications.py
#	test/functional/test_runner.py
#	test/util/rpcauth-test.py
@practicalswift practicalswift deleted the lint-python-utf8-encoding branch April 10, 2021 19:34
UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request May 6, 2021
…t files using UTF-8 encoding in Python

c8176b3 Add linter: Make sure we explicitly open all text files using UTF-8 or ASCII encoding in Python (practicalswift)
634bd97 Explicitly specify encoding when opening text files in Python code (practicalswift)

Pull request description:

  Add linter: Make sure we explicitly open all text files using UTF-8 encoding in Python.

  As requested by @laanwj in bitcoin#13440.

Tree-SHA512: 1651c00fe220ceb273324abd6703aee504029b96c7ef0e3029145901762c733c9b9d24927da281394fd4681a5bff774336c04eed01fafea997bb32192c334c06
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Mar 11, 2022
…t files using UTF-8 encoding in Python

c8176b3 Add linter: Make sure we explicitly open all text files using UTF-8 or ASCII encoding in Python (practicalswift)
634bd97 Explicitly specify encoding when opening text files in Python code (practicalswift)

Pull request description:

  Add linter: Make sure we explicitly open all text files using UTF-8 encoding in Python.

  As requested by @laanwj in bitcoin#13440.

Tree-SHA512: 1651c00fe220ceb273324abd6703aee504029b96c7ef0e3029145901762c733c9b9d24927da281394fd4681a5bff774336c04eed01fafea997bb32192c334c06
Signed-off-by: pasta <[email protected]>
gades pushed a commit to cosanta/cosanta-core that referenced this pull request May 2, 2022
…t files using UTF-8 encoding in Python

c8176b3 Add linter: Make sure we explicitly open all text files using UTF-8 or ASCII encoding in Python (practicalswift)
634bd97 Explicitly specify encoding when opening text files in Python code (practicalswift)

Pull request description:

  Add linter: Make sure we explicitly open all text files using UTF-8 encoding in Python.

  As requested by @laanwj in bitcoin#13440.

Tree-SHA512: 1651c00fe220ceb273324abd6703aee504029b96c7ef0e3029145901762c733c9b9d24927da281394fd4681a5bff774336c04eed01fafea997bb32192c334c06
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants