Coder Social home page Coder Social logo

Comments (6)

malemburg avatar malemburg commented on August 17, 2024 1

I don't think such meta codecs are a good idea, since their meaning depends on the local configuration of the app running the code and can thus behave in undefined ways. The "mbcs" codec we have is similar and has issues, since you don't know what the actual encoding will be. The codec is needed because the Windows C API uses this meta encoding, but it's not ideal.

In the above use case, it's better to use a fixed default encoding such as "utf-8".

You can see that the io sub-system also doesn't use "locale" as encoding, but instead seems to go out to the os.environ to figure out what the locale settings are and then uses whatever this returns for the actual encoding ("utf-8" in case of the example).

PS: In the early days of Python 2 we experimented with using a locale based default encoding and quickly dropped that idea. Explicit is better than implicit...

from cpython.

Zheaoli avatar Zheaoli commented on August 17, 2024

Confirmed in main branch. I'm not sure we need to keep the same behavior for the encoding field in open and codecs.open API. CC @Eclips4

from cpython.

serhiy-storchaka avatar serhiy-storchaka commented on August 17, 2024

3.11 is already in security-only mode. Bug fixes can only be applied for 3.12+.

from cpython.

serhiy-storchaka avatar serhiy-storchaka commented on August 17, 2024

io.text_encoding() was added in 3.10, and the behavior was the same as in 3.11.

So this is rather a new feature request.

from cpython.

Zheaoli avatar Zheaoli commented on August 17, 2024

@serhiy-storchaka May I take handle of this feature request if we confirm this is necessary?

from cpython.

serhiy-storchaka avatar serhiy-storchaka commented on August 17, 2024

@malemburg, what do you think about support of encoding='locale' in codecs streams?

from cpython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.