Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop py37 and py38 support #52

Merged
merged 4 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
id: set-python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.7" # don't forget to update cache key below
python-version: "3.9" # don't forget to update cache key below

- name: Cache pip dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-3.7-pip-${{ hashFiles('**/poetry.lock') }}
key: ${{ runner.os }}-3.9-pip-${{ hashFiles('**/poetry.lock') }}

- name: Cache pre-commit dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }}-${{ hashFiles('**/tox.ini') }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@master
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.9"

- name: Build and Publish package
env:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Cache pip dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('**/poetry.lock') }}

- name: Cache pre-commit dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-${{ matrix.python-version }}-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }}-${{ hashFiles('**/tox.ini') }}
Expand All @@ -52,7 +52,7 @@ jobs:
tox -e coverage -- --fail-under=99

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./test-reports/coverage.xml
Expand Down
6 changes: 5 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
default_language_version:
python: python3
python: python3.9
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.18.0
hooks:
- id: pyupgrade
- repo: https://github.com/ambv/black
rev: 22.6.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion example/app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
todos: Dict[int, "TodoItem"] = {}


class Dispatcher(object):
class Dispatcher:
def create(self, text: str, type: int) -> int:
todo_id = max(todos.keys() or [0]) + 1
created = datetime.datetime.now()
Expand Down
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[mypy]
python_version = 3.7
python_version = 3.9
warn_return_any = True
warn_redundant_casts = True
warn_unused_configs = True
Expand Down
20 changes: 8 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "thrift-pyi"
version = "0.9.0"
version = "1.0.0"
description = "This is simple `.pyi` stubs generator from thrift interfaces"
readme = "README.rst"
repository = "https://github.com/unmade/thrift-pyi"
Expand All @@ -10,11 +10,11 @@ packages = [
{ include = "thriftpyi", from = "src" },
]
classifiers = [
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Topic :: Software Development :: Code Generators",
Expand All @@ -24,22 +24,18 @@ classifiers = [
thriftpyi = "thriftpyi.cli:main"

[tool.poetry.dependencies]
python = "^3.7"
astunparse = {version = "^1.6.3", python = "< 3.9.0" }
python = "^3.9"
autoflake = "*"
black = "*"
thriftpy2 = "^0.4.2"

[tool.poetry.dev-dependencies]
tox = "^3.24"
pre-commit = "^2.20"
mypy = "^0.971"
pylint = [
{version = ">=2.13.9,<2.14.0", python = ">= 3.7.0, < 3.7.2"},
{version = "^2.15", python = ">= 3.7.2, < 4.0.0"},
]
pytest = "^7.1.2"
pytest-cov = "^3.0.0"
mypy = "^1.12"
pylint = "^3.3"
pytest = "^8.3"
pytest-cov = "^5.0"


[build-system]
Expand Down
10 changes: 0 additions & 10 deletions src/thriftpyi/compat.py

This file was deleted.

20 changes: 10 additions & 10 deletions src/thriftpyi/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import ast
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, List, Optional, Sequence, Type, Union
from typing import TYPE_CHECKING, Sequence, Type, Union

if TYPE_CHECKING:
AnyFunctionDef = Union[ast.AsyncFunctionDef, ast.FunctionDef]
Expand All @@ -15,8 +15,8 @@
@dataclass
class ModuleItem:
name: str
fields: List[Field] = field(default_factory=list)
methods: List[Method] = field(default_factory=list)
fields: list[Field] = field(default_factory=list)
methods: list[Method] = field(default_factory=list)

def with_options(
self,
Expand Down Expand Up @@ -53,7 +53,7 @@ def as_ast(
bases = bases or []
decorators = decorators or []

body: List[ast.stmt] = []
body: list[ast.stmt] = []
body.extend(entry.as_ast() for entry in self.fields)
body.extend(entry.as_ast() for entry in self.methods)

Expand All @@ -62,7 +62,7 @@ def as_ast(

return ast.ClassDef(
name=self.name,
bases=[[ast.Name(id=base, ctx=ast.Load())] for base in bases],
bases=[ast.Name(id=base, ctx=ast.Load()) for base in bases],
keywords=[],
body=body,
decorator_list=[
Expand All @@ -74,8 +74,8 @@ def as_ast(
@dataclass
class Method:
name: str
args: List[Field] = field(default_factory=list)
returns: List[Field] = field(default_factory=list)
args: list[Field] = field(default_factory=list)
returns: list[Field] = field(default_factory=list)
is_async: bool = False

def with_options(
Expand Down Expand Up @@ -117,7 +117,7 @@ def as_ast(self) -> AnyFunctionDef:

return factory(
name=self.name,
args=ast.arguments(
args=ast.arguments( # type: ignore[call-overload]
posonlyargs=[],
args=[
ast.arg(arg="self", annotation=None),
Expand All @@ -139,7 +139,7 @@ def as_ast(self) -> AnyFunctionDef:
@dataclass
class Field:
name: str
type: Optional[str]
type: str | None
value: FieldValue
required: bool

Expand All @@ -157,7 +157,7 @@ def with_options(self, *, ignore_optional: bool, ignore_required: bool) -> Field
required=required,
)

def as_ast(self) -> Union[ast.AnnAssign, ast.Assign]:
def as_ast(self) -> ast.AnnAssign | ast.Assign:
if self.type is None:
return ast.Assign(
targets=[ast.Name(id=self.name, ctx=ast.Store())],
Expand Down
5 changes: 2 additions & 3 deletions src/thriftpyi/files.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from __future__ import annotations

from pathlib import Path
from typing import List, Union


def list_interfaces(interfaces_dir: Union[str, Path]) -> List[Path]:
def list_interfaces(interfaces_dir: str | Path) -> list[Path]:
return list(Path(interfaces_dir).glob("**/*.thrift"))


def save(data: str, to: Union[str, Path]) -> None:
def save(data: str, to: str | Path) -> None:
Path.mkdir(Path(to).parent, exist_ok=True)
with open(to, "w+", encoding="utf-8") as f:
f.write(data)
6 changes: 3 additions & 3 deletions src/thriftpyi/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import annotations

import ast
import subprocess
import sys
from pathlib import Path

import thriftpy2

from thriftpyi import files, stubs
from thriftpyi.compat import ast_unparse
from thriftpyi.proxies import TModuleProxy


Expand All @@ -22,7 +22,7 @@ def thriftpyi( # pylint: disable=too-many-locals
interfaces = files.list_interfaces(interfaces_dir)

stub = stubs.build_init(path.stem for path in interfaces)
files.save(ast_unparse(stub), to=output_dir / "__init__.pyi")
files.save(ast.unparse(stub), to=output_dir / "__init__.pyi")

for path in interfaces:
tmodule = thriftpy2.load(str(path))
Expand All @@ -33,7 +33,7 @@ def thriftpyi( # pylint: disable=too-many-locals
strict_fields=strict_fields,
strict_methods=strict_methods,
)
files.save(ast_unparse(stub), to=output_dir / path.with_suffix(".pyi").name)
files.save(ast.unparse(stub), to=output_dir / path.with_suffix(".pyi").name)

lint(output_dir)

Expand Down
18 changes: 9 additions & 9 deletions src/thriftpyi/proxies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import List, Tuple, cast
from typing import cast

from thriftpyi.entities import Field, FieldValue, Method, ModuleItem
from thriftpyi.utils import get_python_type, guess_type
Expand All @@ -12,35 +12,35 @@ class TModuleProxy:
def __init__(self, tmodule) -> None:
self.tmodule = tmodule

def get_consts(self) -> List[Field]:
def get_consts(self) -> list[Field]:
tconsts = (
(name, value)
for name, value in vars(self.tmodule).items()
if value in self.tmodule.__thrift_meta__["consts"]
)
return [self._make_const(tconst) for tconst in tconsts]

def get_enums(self) -> List[ModuleItem]:
def get_enums(self) -> list[ModuleItem]:
return [
self._make_enum(tenum) for tenum in self.tmodule.__thrift_meta__["enums"]
]

def get_exceptions(self) -> List[ModuleItem]:
def get_exceptions(self) -> list[ModuleItem]:
return [
self._make_exception(texc)
for texc in self.tmodule.__thrift_meta__["exceptions"]
]

def get_imports(self) -> List[str]:
def get_imports(self) -> list[str]:
return [item.__name__ for item in self.tmodule.__thrift_meta__["includes"]]

def get_services(self) -> List[ModuleItem]:
def get_services(self) -> list[ModuleItem]:
return [
self._make_service(tservice)
for tservice in self.tmodule.__thrift_meta__["services"]
]

def get_structs(self) -> List[ModuleItem]:
def get_structs(self) -> list[ModuleItem]:
return [
self._make_struct(tstruct)
for tstruct in self.tmodule.__thrift_meta__["structs"]
Expand Down Expand Up @@ -141,7 +141,7 @@ def _make_struct(tclass) -> ModuleItem:
class TSpecItemProxy:
__slots__ = ("ttype", "name", "meta", "required")

def __init__(self, item: Tuple):
def __init__(self, item: tuple):
ttype, name, *meta, required = item
self.ttype = ttype
self.name = name
Expand All @@ -157,7 +157,7 @@ def __init__(self, module_name: str, thrift_spec, default_spec):
self.thrift_spec = [TSpecItemProxy(thrift_spec[k]) for k in sorted(thrift_spec)]
self.default_spec = default_spec

def get_fields(self, *, ignore_type: bool = False) -> List[Field]:
def get_fields(self, *, ignore_type: bool = False) -> list[Field]:
return [
Field(
name=item.name,
Expand Down
Loading