HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
asottile
pyupgrade
Python2019–2024
asottile / pyupgrade

pyupgrade

A tool (and pre-commit hook) to automatically upgrade syntax for newer versions of the language.

10Distinct people
10Mentions
0Explicit recommenders
4.1KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

A tool (and pre-commit hook) to automatically upgrade syntax for newer versions of the language.

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

  • psf/black · linked in 2 of the same discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 3:56:07 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year10 dated mentions

Observed mentions: 2019-08-27 13:58:19 UTC to 2024-09-18 11:21:12 UTC.

0123452019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments20192020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 5 mentions; 1 submissions, 4 comments20212022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2024

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC202
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC000
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC514
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC101
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC101
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC101

What Hacker News says

10 sources
From my advice, try to stay on Python. I am currently doing the opposite. Moving an old Java stack to Python/Django. Been able to do so under 9 months. I think upgrading to Python 3 should be doable. What's the version of your Django stack? You just need to try to reach Django 2.2. And if you are at Django 1.1, 90% of your code can be upgraded to Python 3. Nothing fancy. You just need to use libraries such as pyupgrade [0] to automatically upgrade your code, combined with black [1], flake [2],... Everything is done in less than 20 commits. From there you jump to 2.2 which supports Python 3.6+ . It will be very difficult to implement all the goodies given by Django ORM/SQLAlchemy. But ... You if Java/C# is the tech that you feel confortable with, no problem. You have to use it. But, I really think it's easier to understand the "business d
Read the rest
In Ask HN: Did somebody have success with the migration of Python 2.7 to Java/C#?
pyupgrade seems to do lots of useful stuff; thx for link! I guess you need the `--py36-plus` CLI option to reproduce the desired behaviour https://github.com/asottile/pyupgrade#f-strings thought that might result in lots of other edits to the source, this in particular seems unwarranted "foo".encode("utf-8") --> "foo".encode() because the default encoding in py3+ is utf-8. What happened to explicit is better than implicit?
In Flynt: Convert old Python string formatting to f-strings
You can start porting your live codebase to python 3 right now - no downtime at all. You can have a 2+3 compatible codebase live in a week or two, it'll get you about 98% the way there [1] My projects (e.g. https://tmuxp.git-pull.com, https://unihan-etl.git-pull.com) are both python 2/3 compatible. I learned by reading through other projects like Sphinx, Flask, Werkzeug, and SQLAlchemy: - Flask: https://github.com/pallets/flask - Werkzeug: https://github.com/pallets/werkzeug - Sphinx https://github.com/sphinx-doc/sphinx/tree/v1.8.5 (see compat: https://github.com/sphinx-doc/sphinx/blob/v1.8.5/sphinx/util...) - https://github.com/sqlalchemy/sqlalchemy Helpful blog posts: http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python..., http://lucumr.pocoo.org/2013/5/21/porting-to-python-3-redux/ As for automation tools, for 2/3 compatibili
Read the rest
ty, I used futurize and huge codebase to great success: https://python-future.org/futurize.html. I started with this: futurize --write --stage1 --unicode-literals --nobackups <files> and https://docs.python.org/2/library/2to3.html 2to3-2.7 -w -n <files> Really helped. Also, wire Travis / your CI system to have your tests run on python 2 and 3. If you want to test your python 3 codebase live on a subdomain / same SQL/NoSQL DB, be careful about jobs/tasks! Pickle version mismatches and stuff. Use a separate redis/whatever DB for the deployments. After you're finally on python 3, you can use https://github.com/asottile/pyupgrade to modern your code. [1] For the other 2%, use conditionals in your requirements file: enum34==1.0.4;python_version<"3" ushlex==0.99.1;python_version<"3"
In Go + Services = One Goliath Project
> Git hooks with pre-commit In projects where I am involved in, we usually set up hooks that run a few checks from https://github.com/pre-commit/pre-commit-hooks plus https://github.com/asottile/pyupgrade plus https://github.com/psf/black plus maybe the mypy and flake8 hooks. These hooks are also run in a "lint" stage by by tox, which is also run on the CI system. This catches some lints that slip through every now and then, before you go on to commit them. Also, a tox run will as a side effect also reformat the code before you check it in, which is a nice laziness feature. I am currently thinking if I should move to the pytest plugins for mypy and flake8 because I find they make more sense as tests, especially if I'm developing inside a venv and repeatedly run pytest instead of tox. That would also mean that the mypy and flake8 checks ar
Read the rest
e run repeatedly for every Python interpreter I want to tox, unkess I invest some time into coming up with better TOXENVs. Hm.
In How to set up a perfect Python project

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.