question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

py3-plus: .encode('utf-8') → .encode() & .decode('utf-8') → .decode()

See original GitHub issue

In Python 3, the first positional argument to .encode() and .decode() defaults to 'utf-8'. This was not the case with Python 2:

https://docs.python.org/3/library/stdtypes.html#str.encode https://docs.python.org/3/library/stdtypes.html#bytes.decode

As this is the most common value passed, there could be a transform to simplify the calls to just .encode() or .decode() (without the first positional argument). This could help clean up and simplify modern Python code by removing noise.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
asottilecommented, May 27, 2019

it can, but like, who would write that

1reaction
asottilecommented, May 28, 2019

not yet, I want to finish up a PR first – you can try the latest from git however pip install git+https://github.com/asottile/pyupgrade (or via pre-commit pre-commit try-repo https://github.com/asottile/pyupgrade (to just try) or if you have it already configured pre-commit autoupdate --repo https://github.com/asottile/pyupgrade --bleeding-edge)

Read more comments on GitHub >

github_iconTop Results From Across the Web

utf 8 - How Python decodes UTF8 Encoding in String Format
Use ast.literal_eval() , it's not unsafe. Then you don't need to call bytes() , since it will return a byte string.
Read more >
dart:convert library - Dart API
A Utf8Codec encodes strings to UTF-8 code units (bytes) and decodes UTF-8 code units to strings. The utf8 is the default implementation of...
Read more >
utf8 | Yarn - Package Manager
Unlike many other JavaScript solutions, it is designed to be a proper UTF-8 encoder/decoder: it can encode/decode any scalar Unicode code point values,...
Read more >
Encoding Standard
8.1.1 UTF-8 decoder; 8.1.2 UTF-8 encoder ... The encodeInto() method can be used to encode a string into an existing ArrayBuffer object.
Read more >
Encode a String to UTF-8 in Java
How to do Base64 encoding and decoding in Java, using the new APIs introduced in Java 8 as well as Apache Commons. Read...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found