# PEP-597: Emit a Warning when encoding is omitted

**URL:** <https://discuss.python.org/t/pep-597-emit-a-warning-when-encoding-is-omitted/3880>\
**Category:** PEPs\
**Created:** [April 12, 2020, 3:24am UTC](https://discuss.python.org/t/pep-597-emit-a-warning-when-encoding-is-omitted/3880 "2020-04-12T03:24:55Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![methane](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/methane/32/43_2.png) [@methane](https://discuss.python.org/u/methane)\
**Post date:** [September 7, 2020, 4:22am UTC](https://discuss.python.org/t/pep-597-emit-a-warning-when-encoding-is-omitted/3880/21 "2020-09-07T04:22:57Z")

</div>

I updated the PEP.

> <https://github.com/python/peps/pull/1585>

---

<div class="post-metadata">

**Author:** ![graingert](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/graingert/32/26847_2.png) [@graingert](https://discuss.python.org/u/graingert)\
**Post date:** [September 8, 2020, 9:43pm UTC](https://discuss.python.org/t/pep-597-emit-a-warning-when-encoding-is-omitted/3880/22 "2020-09-08T21:43:43Z")

</div>

might be worth suggesting in the PEP that typeshed use:

```auto
LOCALE_ENCODING: Literal[" __locale_encoding__"] = ... # or whatever the string constant ends up

```

---

<div class="post-metadata">

**Author:** ![vstinner](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/vstinner/32/15130_2.png) [@vstinner](https://discuss.python.org/u/vstinner)\
**Post date:** [November 2, 2020, 11:42pm UTC](https://discuss.python.org/t/pep-597-emit-a-warning-when-encoding-is-omitted/3880/23 "2020-11-02T23:42:40Z")

</div>

I don’t think that it’s a good idea to say “deprecation” if there is no plan to change the default behavior in the future. In past discussions, I understood that we cannot make UTF-8 the default encoding in the near future. We cannot raise an error when the encoding is omitted neither, since it would break too much code.

Would it be possible to use a new very specific warning class, rather than reusing PendingDeprecationWarning? Ideas of warning name:

- DefaultEncodingWarning
- ImplicitEncodingWarning
- NoEncodingWarning
- etc.

A specific warning gives the ability to easily ignore it when you test an application for deprecation warnings, but don’t want to be annoyed by the encoding warnings. Use `-W ignore::DefaultEncodingWarning` command line option or `PYTHONWARNINGS=ignore::DefaultEncodingWarning` environment variable.

It’s not only about the warning class, but also the message sent to Python users. There is no scheduled plan to break their applications soon.

---

<div class="post-metadata">

**Author:** ![methane](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/methane/32/43_2.png) [@methane](https://discuss.python.org/u/methane)\
**Post date:** [November 3, 2020, 5:50am UTC](https://discuss.python.org/t/pep-597-emit-a-warning-when-encoding-is-omitted/3880/24 "2020-11-03T05:50:58Z")

</div>

> [@vstinner](#):
>
> I don’t think that it’s a good idea to say “deprecation” if there is no plan to change the default behavior in the future.

> [@vstinner](#):
>
> It’s not only about the warning class, but also the message sent to Python users. There is no scheduled plan to break their applications soon.

But it is why there is PendingDeprecationWarning. If we have actual removal/changing plan, it should be DeprecationWarning or FutureWarning.

“Pending” means “there is no actual plan to remove/change it”. So using PendingDeprecationWarning totally makes sense to me.

> [@vstinner](#):
>
> A specific warning gives the ability to easily ignore it when you test an application for deprecation warnings, but don’t want to be annoyed by the encoding warnings. Use `-W ignore::DefaultEncodingWarning` command line option or `PYTHONWARNINGS=ignore::DefaultEncodingWarning` environment variable.

I am not sure that merits is enough to adding one more builtin exception class.  
I can not imagine users want to fix PendingDeprecationWarning, but ignore use of default text encoding. I want to notice all warnings and fix as many as possible when I use `-Xdev` mode, `-Wd`, or `PYTHONWARNINGS=default`.

---

<div class="post-metadata">

**Author:** ![vstinner](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/vstinner/32/15130_2.png) [@vstinner](https://discuss.python.org/u/vstinner)\
**Post date:** [November 9, 2020, 8:03am UTC](https://discuss.python.org/t/pep-597-emit-a-warning-when-encoding-is-omitted/3880/25 "2020-11-09T08:03:42Z")

</div>

People are proposing to make UTF-8 the default since we started to discuss Python 3.0. 12 years after the release of Python 3.0, we still get new issues with special locale configurations on Linux. Python uses UTF-8 on Windows, macOS, Android and VxWorks for the filesystem encoding. On Linux and FreeBSD, it still uses the locale encoding: [Python Initialization Configuration — Python 3.13.0a2 documentation](https://docs.python.org/dev/c-api/init_config.html#c.PyConfig.filesystem_encoding)

Maybe in 10 years, it will be obvious to use UTF-8 by default on all platforms. But in 2020, it remains a controversial question (see discussions on my previous attempts to switch to UTF-8 by default last year).

IMO PendingDeprecationWarning means an incoming incompatible change, which is not the case here. This problem is important enough to require a new specific warning class.

> “Pending” means “there is no actual plan to remove/change it”. So using PendingDeprecationWarning totally makes sense to me.

Usually, a PendingDeprecationWarning in introduced in Python version N, then replaced with DeprecatedWarning in version N+1, to finally remove the feature in version N+2. Sometimes, PendingDeprecationWarning in introduced after a final 3.x.0 final, in a bugfix release. But there is no general rule.

> **[PEP 387 – Backwards Compatibility Policy | peps.python.org](https://peps.python.org/pep-0387/)**
>
> Python Enhancement Proposals (PEPs)

---

<div class="post-metadata">

**Author:** ![methane](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/methane/32/43_2.png) [@methane](https://discuss.python.org/u/methane)\
**Post date:** [November 9, 2020, 9:56am UTC](https://discuss.python.org/t/pep-597-emit-a-warning-when-encoding-is-omitted/3880/26 "2020-11-09T09:56:50Z")

</div>

> [@vstinner](#):
>
> IMO PendingDeprecationWarning means an incoming incompatible change, which is not the case here.

> [@vstinner](#):
>
> Usually, a PendingDeprecationWarning in introduced in Python version N, then replaced with DeprecatedWarning in version N+1, to finally remove the feature in version N+2. Sometimes, PendingDeprecationWarning in introduced after a final 3.x.0 final, in a bugfix release. But there is no general rule.

Didn’t we agree that we should use DeprecationWarning from first last year?

Previous discussion:

[https://mail.python.org/archives/list/python-dev@python.org/thread/PE57K2XE2SWKNWKJQNMB3XNEU2BEAVIC/](https://mail.python.org/archives/list/python-dev@python.org/thread/PE57K2XE2SWKNWKJQNMB3XNEU2BEAVIC/)

Current note in the document:

> <https://github.com/python/cpython/commit/86fbe0287dd774022fd2b6c2dcbfbb5573a0b874>
>
> (cherry picked from commit 176d26364bb67801fa522f52f20cbe44420d6942)
> 
> Co-authore…d-by: Inada Naoki \<songofacandy@gmail.com\>

> [@vstinner](#):
>
> This problem is important enough to require a new specific warning class.

Introducing new Warning class will affects warning filter configurations. We already have different default rules for DeprecationWarning and PendingDefaultWarning. We have special care in tests. Third party libraries too.

So I didn’t want to introduce a new warning class, especially until we emit the warning only in dev mode. If we abandon to changing the default encoding, but just wait all system in the world become UTF-8 locale, the new Warning class and filter rules are technical debt.

But if the new Warning class is subclass of the DeprecationWarning, we may able to avoid making filter rules more complicated. How do you think this subclassing?

For naming, if we want to use the warning only for this specific purpose, verbose name is preferred since we have much XxxxEncoding (FS, Locale, Default, PYTHONIOENCODING etc…)  
For example, “TextIOEncodingWarning” or “DefaultTextIOEncoding”.

---

<div class="post-metadata">

**Author:** ![methane](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/methane/32/43_2.png) [@methane](https://discuss.python.org/u/methane)\
**Post date:** [January 30, 2021, 11:30am UTC](https://discuss.python.org/t/pep-597-emit-a-warning-when-encoding-is-omitted/3880/27 "2021-01-30T11:30:26Z")

</div>

I updated the PEP 597. I added EncodingWarning and option to enable it.

- EncodingWarning, like BytesWarning
- -X warn\_encoding or PYTHONWARNENCODING to enable it.

---

<div class="post-metadata">

**Author:** ![methane](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/methane/32/43_2.png) [@methane](https://discuss.python.org/u/methane)\
**Post date:** [February 1, 2021, 5:52am UTC](https://discuss.python.org/t/pep-597-emit-a-warning-when-encoding-is-omitted/3880/28 "2021-02-01T05:52:45Z")

</div>

I created new thread on python-dev ML for the updated PEP.

[https://mail.python.org/archives/list/python-dev@python.org/thread/SFYUP2TWD5JZ5KDLVSTZ44GWKVY4YNCV/](https://mail.python.org/archives/list/python-dev@python.org/thread/SFYUP2TWD5JZ5KDLVSTZ44GWKVY4YNCV/)

[Previous page](https://discuss.python.org/t/pep-597-emit-a-warning-when-encoding-is-omitted/3880.md?page=1)
