Skip to content

Commit f211e4b

Browse files
authored
Fix: Incorrect use of typing.Union (#11)
fix: Incorrect use typing.Union feat: support from python3.8 ci: use tox
1 parent 6704a52 commit f211e4b

File tree

5 files changed

+78
-61
lines changed

5 files changed

+78
-61
lines changed

.github/workflows/ci.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "master", "ci/*" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
name: ci ${{ matrix.python-version }}
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Setup Go environment
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version: '1.22'
25+
cache-dependency-path: tests/clients/go/go.sum
26+
- name: Setup Java JDK
27+
uses: actions/setup-java@v4
28+
with:
29+
distribution: temurin
30+
java-version: 22
31+
cache: maven
32+
cache-dependency-path: tests/clients/java/pom.xml
33+
- name: Set up Python
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: ${{ matrix.python-version }}
37+
allow-prereleases: true
38+
check-latest: true
39+
- name: Install dependencies
40+
run: |
41+
sudo apt install libmaxminddb0 libmaxminddb-dev
42+
python -m pip install --upgrade pip
43+
pip install tox
44+
- name: Test
45+
run: tox -e py
46+
- name: Lint
47+
if: matrix.python-version == '3.12'
48+
run: tox -e lint

.github/workflows/python.yml

-48
This file was deleted.

mmdb_writer.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.2.1"
1+
__version__ = "0.2.2"
22

33
import logging
44
import math
@@ -23,7 +23,7 @@ def __init__(self, value: float):
2323

2424

2525
class MmdbF64(MmdbBaseType):
26-
def __init__(self, value: Union[float | Decimal]):
26+
def __init__(self, value: Union[float, Decimal]):
2727
super().__init__(value)
2828

2929

@@ -145,14 +145,14 @@ def __repr__(self):
145145
"uint64",
146146
"uint128",
147147
"int32",
148-
]
149-
| MmdbU16
150-
| MmdbU32
151-
| MmdbU64
152-
| MmdbU128
153-
| MmdbI32
148+
],
149+
MmdbU16,
150+
MmdbU32,
151+
MmdbU64,
152+
MmdbU128,
153+
MmdbI32,
154154
]
155-
FloatType = Union[Literal["f32", "f64", "float32", "float64"] | MmdbF32 | MmdbF64]
155+
FloatType = Union[Literal["f32", "f64", "float32", "float64"], MmdbF32, MmdbF64]
156156

157157

158158
class Encoder:
@@ -547,7 +547,7 @@ def __init__(
547547
ip_version=4,
548548
database_type="GeoIP",
549549
languages: List[str] = None,
550-
description: Union[Dict[str, str] | str] = "GeoIP db",
550+
description: Union[Dict[str, str], str] = "GeoIP db",
551551
ipv4_compatible=False,
552552
int_type: IntType = "auto",
553553
float_type: FloatType = "f64",

pyproject.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "mmdb_writer"
77
description = "Make `mmdb` format ip library file which can be read by maxmind official language reader"
88
readme = "README.md"
99
license = {file = "LICENSE"}
10-
requires-python = ">=3.6"
10+
requires-python = ">=3.8"
1111
keywords = ["mmdb", "maxmind"]
1212
authors = [{ name = "VimT", email = "[email protected]" } ]
1313
classifiers = [
@@ -16,8 +16,9 @@ classifiers = [
1616
"License :: OSI Approved :: MIT License",
1717
"Natural Language :: English",
1818
"Operating System :: OS Independent",
19-
"Programming Language :: Python :: 3.6",
20-
"Programming Language :: Python :: 3.7",
19+
"Programming Language :: Python",
20+
"Programming Language :: Python :: 3",
21+
"Programming Language :: Python :: 3 :: Only",
2122
"Programming Language :: Python :: 3.8",
2223
"Programming Language :: Python :: 3.9",
2324
"Programming Language :: Python :: 3.10",

tox.ini

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tox]
2+
envlist =
3+
py3{13,12,11,10,9,8}
4+
lint
5+
skip_missing_interpreters = true
6+
7+
[testenv]
8+
description = run unit tests
9+
extras = test
10+
commands = pytest
11+
12+
[testenv:lint]
13+
extras = dev
14+
commands =
15+
ruff check --no-fix
16+
ruff format --check

0 commit comments

Comments
 (0)