# Str(mybytes): wrong docs?

**URL:** <https://discuss.python.org/t/str-mybytes-wrong-docs/2866>\
**Category:** Python Help\
**Created:** [December 14, 2019, 10:07pm UTC](https://discuss.python.org/t/str-mybytes-wrong-docs/2866 "2019-12-14T22:07:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Sulla](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/marco_sulla/32/1451_2.png) [@Marco\_Sulla](https://discuss.python.org/u/Marco_Sulla)\
**Post date:** [December 14, 2019, 10:07pm UTC](https://discuss.python.org/t/str-mybytes-wrong-docs/2866/1 "2019-12-14T22:07:26Z")

</div>

In the [official documentation](https://docs.python.org/3.9/library/stdtypes.html#str), the signature for `str()` passing a `bytes` object is:

> _class_ `str` ( _object=b’’_ , _encoding=‘utf-8’_ , _errors=‘strict’_ )

But the documentation says:

> If at least one of _encoding_ or _errors_ is given, […] then `str(bytes, encoding, errors)` is equivalent to [`bytes.decode(encoding, errors)`](https://docs.python.org/3.9/library/stdtypes.html#bytes.decode). […]
> 
> Passing a [`bytes`](https://docs.python.org/3.9/library/stdtypes.html#bytes) object to [`str()`](https://docs.python.org/3.9/library/stdtypes.html#str) without the _encoding_ or _errors_ arguments falls under the first case of returning the informal string representation

Indeed I tested it in REPL and the docs are correct. But in this case, I suppose the correct signature of the class is:

> _class_ `str` ( _object=b’’_ , _encoding=None_ , _errors=None_ )  
> _class_ `str` ( _object=b’’_ [, _encoding_ [, _errors_] ] )

as `help(str)` reports.

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [December 14, 2019, 10:35pm UTC](https://discuss.python.org/t/str-mybytes-wrong-docs/2866/2 "2019-12-14T22:35:42Z")

</div>

If the docs are correct, why do you want to change the documented  
signature?

`encoding = None` is not a valid encoding:

```
> str(b'abcd', encoding=None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: str() argument 2 must be str, not None
```

---

<div class="post-metadata">

**Author:** ![Marco\_Sulla](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/marco_sulla/32/1451_2.png) [@Marco\_Sulla](https://discuss.python.org/u/Marco_Sulla)\
**Post date:** [December 14, 2019, 10:57pm UTC](https://discuss.python.org/t/str-mybytes-wrong-docs/2866/3 "2019-12-14T22:57:24Z")

</div>

The docs says that if encoding or errors is given, then [`bytes.decode(encoding, errors)`](https://docs.python.org/3.9/library/stdtypes.html#bytes.decode) is used.

But the signatures says that `encoding` is `'utf-8'` by default and `errors` is `'strict'` by default.

If the signature is correct, the default behavior will be using `bytes.decode("utf-8", "strict")`. But this is not true.

---

<div class="post-metadata">

**Author:** ![Marco\_Sulla](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/marco_sulla/32/1451_2.png) [@Marco\_Sulla](https://discuss.python.org/u/Marco_Sulla)\
**Post date:** [December 14, 2019, 11:10pm UTC](https://discuss.python.org/t/str-mybytes-wrong-docs/2866/4 "2019-12-14T23:10:44Z")

</div>

In REPL, `help(str)` returns:

> str(bytes\_or\_buffer[, encoding[, errors]])

so I think this is the correct signature.
