Implement #3956 - initial coding hint support#3957
Conversation
for more information, see https://pre-commit.ci
|
I've opened this to generate discussion.
|
|
Would it make sense to use a PEP 263-style regular expression to match encoding declarations? ^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)That would support both Also, if dictionary comment lines are supported in the future, encoding declarations should be checked before skipping comments. This is related to #3915. |
|
@AlightSoulmate I don't think I've ever seen I'd recommend against the regex unless a simple string match isn't possible for the usual reasons. Also I don't have a Regex License https://regexlicensing.org/ 😝 |
|
Doesn't |
@DimitriPapadopoulos we can probably agree that charset is supposed to detect encoding, we may have different experiences in how well it does it 😆 However, this topic isn't about detection, it's about declarations, there's nothing to detect. This PR adds code to honor the very common (and old) character encoding declaration, sometimes named "hints". I personally have zero interest in detection support, it's not reliable enough in my experience to be worth the effort of implementation nor the runtime expense of running the code. |
|
I understand, but shouldn't we spend time fixing |
|
@DimitriPapadopoulos I want to make sure I understand what you are suggesting; I think you are saying to open an enhancement idea in https://github.com/chardet/chardet (https://pypi.org/project/chardet/)? I think that's a good idea, I also think it is reasonable for codespell to do the check encoding hit check (which is not the same function that chardet implements, chardet was originally written for incorrect or missing declarations). There is existing utf-8 and latin1 check code in codespell, so this is consistent with some basic sanity checks. I do not know how your chardet idea would be received by the chardet project, but it's worth trying as well. I'm also unclear how well chardet works in codespell (and I'm not motivated to dig into this). |
No description provided.