On Fri, Feb 12, 2021 at 6:34 AM Paul Moore <p.f.mo...@gmail.com> wrote:
>
> On Thu, 11 Feb 2021 at 21:05, Jim J. Jewett <jimjjew...@gmail.com> wrote:
> >
> > Who will benefit from this new warning?
> >
> > Is this basically just changing builtins.open by adding:
> >
> >     if encoding is None and sys.flags.encoding_warning: # and not Android 
> > and not -X utf8 ?
> >         warnings.warn(EncodingWarning("Are you sure you want locale instead 
> > of utf-8?"))
> >
> > Even for the few people with the knowledge, time, interest, and authority 
> > to fix the code, is that really helpful?
> >
> > Helpful enough to put it directly in python as an optional mode, separate 
> > from the dev mode or show all warnings mode?  Why not just add it to a 
> > linter, or write a 2to3 style checker?  Or at least emit or not based on a 
> > warnings filter?
>
> That's a very good point. If this warning is of use, why have none of
> the well-known linters implemented it? And why not prototype the
> proposal in them, at least? Python-ideas posts routinely get pushed to
> justify "why can't this be done in an external library?" and that
> probably applies here too.
>

* Linters can not add `encoding="locale"` to Python.
* This PEP provides the way to shift where warnings  is emitted.

def my_read_file(filename, encoding=None):
    encoding = io.text_encoding(encoding)
    with open(filename, encoding=encoding) with f:
        return f.read()

This function is not warned. Caller of this function is warned
instead. It is difficult to implement in the Linter.

-- 
Inada Naoki  <songofaca...@gmail.com>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/CKMRUBEI3UHEXSELZIQBA6NZCK77O75T/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to