Skip to content

Commit

Permalink
Remove Python 3.8 support and update source to 3.9 standards (#18687)
Browse files Browse the repository at this point in the history
* manual python 3.8 removals

* poetry

* pyupgrade

* black

* isort

* manually tidy imports

* work around shadowed type

* catch up build network protocol files for pyupgrade changes

* placate pylint

* re-enable 20.04

* placate flake8
  • Loading branch information
altendky authored Oct 16, 2024
1 parent 3ce4acb commit 9c8557a
Show file tree
Hide file tree
Showing 549 changed files with 6,044 additions and 6,237 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/check_wheel_availability.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,8 @@ jobs:
matrix: arm
- name: Intel
matrix: intel
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
exclude:
- os:
matrix: macos
arch:
matrix: arm
python-version: "3.8"
- os:
matrix: windows
arch:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ jobs:
- name: Intel
matrix: intel
python:
- major_dot_minor: "3.8"
- major_dot_minor: "3.9"
- major_dot_minor: "3.10"
- major_dot_minor: "3.11"
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/test-install-scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,12 @@ jobs:
apt-get install --yes software-properties-common
add-apt-repository --yes ppa:git-core/ppa
apt-get --yes update
apt-get install --yes git lsb-release sudo python3-venv
apt-get install --yes git lsb-release sudo
MINIMUM=3.9
if ! apt satisfy --yes "python3-venv (>= ${MINIMUM})"
then
apt-get install --yes python${MINIMUM}-venv
fi
- name: Add safe git directory
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
Expand Down
13 changes: 0 additions & 13 deletions .github/workflows/test-single.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ jobs:
arch:
- matrix: ${{ inputs.arch }}
python:
- name: "3.8"
file_name: "3.8"
action: "3.8"
apt: "3.8"
install_sh: "3.8"
matrix: "3.8"
exclude_from:
limited: True
main: True
- name: "3.9"
file_name: "3.9"
action: "3.9"
Expand Down Expand Up @@ -109,10 +100,6 @@ jobs:
limited: True
main: True
exclude:
- os:
matrix: macos
python:
matrix: "3.8"
- arch:
matrix: arm
configuration:
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/upload-pypi-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jobs:
- name: Intel
matrix: intel
python:
- major_dot_minor: "3.8"
- major_dot_minor: "3.9"
- major_dot_minor: "3.10"
- major_dot_minor: "3.11"
Expand All @@ -68,12 +67,6 @@ jobs:
python manage-mypy.py build-mypy-ini
mypy
exclude:
- os:
matrix: macos
arch:
matrix: arm
python:
major_dot_minor: "3.8"
- os:
matrix: windows
arch:
Expand Down Expand Up @@ -174,7 +167,7 @@ jobs:
- check
strategy:
matrix:
python-version: [3.8]
python-version: [3.10]
os: [ubuntu-latest]

steps:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
hooks:
- id: pyupgrade
name: pyupgrade
entry: ./activated.py pyupgrade --py38-plus --keep-runtime-typing
entry: ./activated.py pyupgrade --py39-plus --keep-runtime-typing
language: system
types: [python]
- repo: local
Expand Down
2 changes: 1 addition & 1 deletion Install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if ($null -eq (Get-Command py -ErrorAction SilentlyContinue))
Exit 1
}

$supportedPythonVersions = "3.12", "3.11", "3.10", "3.9", "3.8"
$supportedPythonVersions = "3.12", "3.11", "3.10", "3.9"
if ("$env:INSTALL_PYTHON_VERSION" -ne "")
{
$pythonVersion = $env:INSTALL_PYTHON_VERSION
Expand Down
5 changes: 2 additions & 3 deletions PRETTY_GOOD_PRACTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ How about a couple examples.
```python
import json
from dataclasses import dataclass
from typing import Type, TypeVar
from typing import TypeVar


_T_Coin = TypeVar("_T_Coin", bound="Coin")
Expand Down Expand Up @@ -281,7 +281,6 @@ If it is hard to deal with the knock on complaints from mypy triggered by the hi
### Basic hints

```python
from typing import List

def sum_bigger_values(values: List[int], minimum: int) -> int:
return sum(value for value in values if value > minimum)
Expand Down Expand Up @@ -497,7 +496,7 @@ Without writing an implementation, let's see what part of a cache leveraging gen

```python
from dataclasses import dataclass, field
from typing import Dict, Generic, Optional, TypeVar
from typing import Generic, Optional, TypeVar

KT = TypeVar("KT")
VT = TypeVar("VT")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Chia is a modern cryptocurrency built from scratch, designed to be efficient, de

Please check out the [Chia website][link-chia], the [Intro to Chia][link-intro], and [FAQ][link-faq] for information on this project.

Python 3.8.1+ is required. Make sure your default python version is >=3.8.1 by typing `python3`.
Python 3.9+ is required. Make sure your default python version is >=3.9 by typing `python3`.

If you are behind a NAT, it can be difficult for peers outside your subnet to reach you when they start up. You can enable [UPnP][link-upnp]
on your router or add a NAT (for IPv4 but not IPv6) and firewall rules to allow TCP port 8444 access to your peer.
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/block_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass
from pathlib import Path
from time import monotonic
from typing import List, Optional
from typing import Optional

import aiosqlite
import click
Expand Down Expand Up @@ -38,10 +38,10 @@
class BlockInfo:
prev_header_hash: bytes32
transactions_generator: Optional[SerializedProgram]
transactions_generator_ref_list: List[uint32]
transactions_generator_ref_list: list[uint32]


def random_refs() -> List[uint32]:
def random_refs() -> list[uint32]:
ret = random.sample(transaction_block_heights, DEFAULT_CONSTANTS.MAX_GENERATOR_REF_LIST_SIZE)
random.shuffle(ret)
return [uint32(i) for i in ret]
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/block_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import sys
from pathlib import Path
from time import monotonic
from typing import List

from benchmarks.utils import setup_db
from chia._tests.util.benchmarks import (
Expand Down Expand Up @@ -72,7 +71,7 @@ async def run_add_block_benchmark(version: int) -> None:
if verbose:
print("profiling add_full_block", end="")

tx_block_heights: List[uint32] = []
tx_block_heights: list[uint32] = []

for height in range(block_height, block_height + NUM_ITERS):
is_transaction = transaction_block_counter == 0
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/blockchains.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import asyncio
import cProfile
import time
from collections.abc import Iterator
from contextlib import contextmanager
from subprocess import check_call
from typing import Iterator

from chia._tests.util.blockchain import persistent_blocks
from chia.simulator.block_tools import create_block_tools_async, test_constants
Expand Down
11 changes: 5 additions & 6 deletions benchmarks/coin_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import sys
from pathlib import Path
from time import monotonic
from typing import List, Tuple

from benchmarks.utils import setup_db
from chia._tests.util.benchmarks import rand_hash, rewards
Expand All @@ -28,9 +27,9 @@ def make_coin() -> Coin:
return Coin(rand_hash(), rand_hash(), uint64(1))


def make_coins(num: int) -> Tuple[List[Coin], List[bytes32]]:
additions: List[Coin] = []
hashes: List[bytes32] = []
def make_coins(num: int) -> tuple[list[Coin], list[bytes32]]:
additions: list[Coin] = []
hashes: list[bytes32] = []
for i in range(num):
c = make_coin()
additions.append(c)
Expand All @@ -48,8 +47,8 @@ async def run_new_block_benchmark(version: int) -> None:
async with setup_db("coin-store-benchmark.db", version) as db_wrapper:
coin_store = await CoinStore.create(db_wrapper)

all_unspent: List[bytes32] = []
all_coins: List[bytes32] = []
all_unspent: list[bytes32] = []
all_coins: list[bytes32] = []

block_height = 1
timestamp = 1631794488
Expand Down
9 changes: 5 additions & 4 deletions benchmarks/mempool-long-lived.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from __future__ import annotations

import asyncio
from collections.abc import Collection
from dataclasses import dataclass
from time import monotonic
from typing import Collection, Dict, List, Optional
from typing import Optional

from chia_rs import G2Element
from clvm.casts import int_to_bytes
Expand Down Expand Up @@ -79,10 +80,10 @@ def fake_block_record(block_height: uint32, timestamp: uint64) -> BenchBlockReco


async def run_mempool_benchmark() -> None:
coin_records: Dict[bytes32, CoinRecord] = {}
coin_records: dict[bytes32, CoinRecord] = {}

async def get_coin_record(coin_ids: Collection[bytes32]) -> List[CoinRecord]:
ret: List[CoinRecord] = []
async def get_coin_record(coin_ids: Collection[bytes32]) -> list[CoinRecord]:
ret: list[CoinRecord] = []
for name in coin_ids:
r = coin_records.get(name)
if r is not None:
Expand Down
21 changes: 11 additions & 10 deletions benchmarks/mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import asyncio
import cProfile
from collections.abc import Collection, Iterator
from contextlib import contextmanager
from dataclasses import dataclass
from subprocess import check_call
from time import monotonic
from typing import Collection, Dict, Iterator, List, Optional, Tuple
from typing import Optional

from chia.consensus.coinbase import create_farmer_coin, create_pool_coin
from chia.consensus.default_constants import DEFAULT_CONSTANTS
Expand Down Expand Up @@ -77,10 +78,10 @@ def fake_block_record(block_height: uint32, timestamp: uint64) -> BenchBlockReco


async def run_mempool_benchmark() -> None:
all_coins: Dict[bytes32, CoinRecord] = {}
all_coins: dict[bytes32, CoinRecord] = {}

async def get_coin_records(coin_ids: Collection[bytes32]) -> List[CoinRecord]:
ret: List[CoinRecord] = []
async def get_coin_records(coin_ids: Collection[bytes32]) -> list[CoinRecord]:
ret: list[CoinRecord] = []
for name in coin_ids:
r = all_coins.get(name)
if r is not None:
Expand All @@ -93,14 +94,14 @@ async def get_unspent_lineage_info_for_puzzle_hash(_: bytes32) -> Optional[Unspe

wt = WalletTool(DEFAULT_CONSTANTS)

spend_bundles: List[List[SpendBundle]] = []
spend_bundles: list[list[SpendBundle]] = []

# these spend the same coins as spend_bundles but with a higher fee
replacement_spend_bundles: List[List[SpendBundle]] = []
replacement_spend_bundles: list[list[SpendBundle]] = []

# these spend the same coins as spend_bundles, but they are organized in
# much larger bundles
large_spend_bundles: List[List[SpendBundle]] = []
large_spend_bundles: list[list[SpendBundle]] = []

timestamp = uint64(1631794488)

Expand All @@ -110,7 +111,7 @@ async def get_unspent_lineage_info_for_puzzle_hash(_: bytes32) -> Optional[Unspe
for peer in range(NUM_PEERS):
print(f" peer {peer}")
print(" reward coins")
unspent: List[Coin] = []
unspent: list[Coin] = []
for idx in range(NUM_ITERS):
height = uint32(height + 1)

Expand Down Expand Up @@ -170,7 +171,7 @@ async def get_unspent_lineage_info_for_puzzle_hash(_: bytes32) -> Optional[Unspe
rec = fake_block_record(height, timestamp)
await mempool.new_peak(rec, None)

async def add_spend_bundles(spend_bundles: List[SpendBundle]) -> None:
async def add_spend_bundles(spend_bundles: list[SpendBundle]) -> None:
for tx in spend_bundles:
spend_bundle_id = tx.name()
npc = await mempool.pre_validate_spendbundle(tx, spend_bundle_id)
Expand Down Expand Up @@ -239,7 +240,7 @@ async def add_spend_bundles(spend_bundles: List[SpendBundle]) -> None:
print(f" per call: {(stop - start) / 500 * 1000:0.2f}ms")

print("\nProfiling new_peak() (optimized)")
blocks: List[Tuple[BenchBlockRecord, List[bytes32]]] = []
blocks: list[tuple[BenchBlockRecord, list[bytes32]]] = []
for coin_id in all_coins.keys():
height = uint32(height + 1)
timestamp = uint64(timestamp + 19)
Expand Down
Loading

0 comments on commit 9c8557a

Please sign in to comment.