Qix- / better-exceptions

Pretty and useful exceptions in Python, automatically.
MIT License
4.59k stars 203 forks source link

Use stream encoding instead of locale preferred encoding #88

Closed Delgan closed 1 year ago

Delgan commented 5 years ago

Hi.

This is intended to fix #53, finally. :)

As discussed, I replaced locale.getpreferredencoding() with STREAM.encoding. Just in case, I added a fallback to ascii if STREAM has no or invalid encoding attribute. For the tests, the encoding can be configured with the PYTHONIOENCODING environment variable in place of LANG and LC_ALL. Also, I had to remove encoding.py and include it directly into color.py to avoid circular dependency.

Hopefully, this should solve reported encoding issues. ;)

Qix- commented 4 years ago

@delgan does this supercede #69?

Delgan commented 4 years ago

@Delgan does this supercede #69?

@Qix- There is definitely overlap between #88 and #69, but #69 tried to go further by removing a bunch of hacky functions used for Python 2 compatibility with colorama. Re-reading what I commented on the PR at that time, it seems this was mostly personal convictions about how encoding should be done. This did not solve any actual issue, so it's ok to merge #88 and reject #69 (I could simply re-implement the changes in the future if needed).

Qix- commented 4 years ago

Sounds good :)

danyeaw commented 1 year ago

PEP597 Encoding Warnings gives warnings about locale preferred encoding if you have the warnings enabled. What needs to happen to get this PR merged?

Qix- commented 1 year ago

Just a rebase on top of current master. I'm out of the country at the moment so my capacity for code changes is low. If @Delgan does a rebase or if you submit a new PR that is rebased I'll accept it, though it'll be a little bit before I can do a release.

Delgan commented 1 year ago

Hey there. :)

I just rebased the PR. :+1: It's quite old, but I first glance, it seems the proposed workaround is still relevant.

Qix- commented 1 year ago

It's going to be a little bit before I can push a release, sorry in advance. @Delgan if you're interested in being added as a pypi maintainer just let me know what your pypi username is.

Delgan commented 1 year ago

@Qix- Thank you for your trust, but I honestly prefer not to handle the administrative part. Let me know if you need help with other developments, though. I would be happy to contribute. :+1: