Skip to content

Commit 5fcf786

Browse files
Use Ruff, fix various tests, deprecate useless function (#92)
1 parent e8092d6 commit 5fcf786

13 files changed

+169
-120
lines changed

.github/workflows/publish.yml

+24-24
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@ jobs:
1010
name: Build and publish Python distributions to PyPI and TestPyPI
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
14-
- name: Set up Python 3.10
15-
uses: actions/setup-python@v4
16-
with:
17-
python-version: "3.10"
18-
- name: Install pypa/build
19-
run: >-
20-
python -m
21-
pip install
22-
build
23-
--user
24-
- name: Build a binary wheel and a source tarball
25-
run: >-
26-
python -m
27-
build
28-
--sdist
29-
--wheel
30-
--outdir dist/
31-
.
32-
- name: Publish distribution to PyPI
33-
if: startsWith(github.ref, 'refs/tags')
34-
uses: pypa/gh-action-pypi-publish@master
35-
with:
36-
password: ${{ secrets.PYPI_API_TOKEN }}
13+
- uses: actions/checkout@v3
14+
- name: Set up Python 3.10
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: "3.10"
18+
- name: Install pypa/build
19+
run: >-
20+
python -m
21+
pip install
22+
build
23+
--user
24+
- name: Build a binary wheel and a source tarball
25+
run: >-
26+
python -m
27+
build
28+
--sdist
29+
--wheel
30+
--outdir dist/
31+
.
32+
- name: Publish distribution to PyPI
33+
if: startsWith(github.ref, 'refs/tags')
34+
uses: pypa/gh-action-pypi-publish@master
35+
with:
36+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/test.yml

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"]
12+
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
1313

1414
steps:
15-
- uses: actions/checkout@v3
16-
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v4
18-
with:
19-
python-version: ${{ matrix.python-version }}
20-
allow-prereleases: true
21-
- name: Install dependencies
22-
run: |
23-
python -m pip install --upgrade pip
24-
pip install tox tox-gh-actions
25-
- name: Test with tox
26-
run: tox
15+
- uses: actions/checkout@v3
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
allow-prereleases: true
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install tox tox-gh-actions
25+
- name: Test with tox
26+
run: tox

.pre-commit-config.yaml

+28-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.2.1
4+
hooks:
5+
- id: ruff
6+
args: [--fix]
7+
28
- repo: https://github.com/psf/black
3-
rev: 24.1.1
9+
rev: 24.2.0
410
hooks:
511
- id: black
6-
language_version: python3.9
7-
8-
ci:
9-
autofix_commit_msg: '[pre-commit.ci] auto fixes from pre-commit.com hooks'
10-
autofix_prs: true
11-
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
12-
autoupdate_schedule: weekly
13-
skip: []
14-
submodules: false
12+
language_version: python3.12
13+
14+
- repo: https://github.com/pre-commit/mirrors-mypy
15+
rev: v1.8.0
16+
hooks:
17+
- id: mypy
18+
additional_dependencies:
19+
- types-requests
20+
- aiohttp
21+
exclude: ^(typeshed_client/typeshed|tests/(site-packages|typeshed))/
22+
23+
- repo: https://github.com/pre-commit/mirrors-prettier
24+
rev: v4.0.0-alpha.8
25+
hooks:
26+
- id: prettier
27+
28+
- repo: https://github.com/pre-commit/pre-commit-hooks
29+
rev: v4.5.0
30+
hooks:
31+
- id: end-of-file-fixer
32+
- id: trailing-whitespace

README.rst

+5
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ call ``resolver.get_fully_qualified_name('collections.Set')`` to retrieve the
8181
Changelog
8282
---------
8383

84+
Unreleased
85+
86+
- Drop support for Python 3.7
87+
- ``typeshed_client.finder.get_search_path()`` is now deprecated, as it is no longer useful
88+
8489
Version 2.4.0 (September 29, 2023)
8590

8691
- Update bundled typeshed

pyproject.toml

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.black]
2-
target_version = ['py37', 'py38', 'py39', 'py310', 'py311']
2+
target_version = ['py38', 'py39', 'py310', 'py311', 'py312']
33
include = '\.pyi?$'
44
skip-magic-trailing-comma = true
55
preview = true
@@ -50,7 +50,45 @@ disallow_any_decorated = true
5050

5151
exclude = [
5252
"typeshed_client/typeshed",
53+
"tests/site-packages",
5354
"tests/typeshed",
5455
"build/",
56+
"thirdparty",
5557
".tox/",
5658
]
59+
60+
[tool.ruff]
61+
62+
line-length = 100
63+
target-version = "py38"
64+
preview = true
65+
unsafe-fixes = true
66+
67+
exclude = [
68+
"typeshed_client/typeshed",
69+
"tests/typeshed",
70+
"build/",
71+
".tox/",
72+
]
73+
74+
[tool.ruff.lint]
75+
select = [
76+
"F",
77+
"E",
78+
"I", # import sorting
79+
"ANN", # enforce type annotations
80+
"C4", # flake8-comprehensions
81+
"B", # bugbear
82+
"SIM", # simplify
83+
"UP", # pyupgrade
84+
"PIE",
85+
"PERF",
86+
"RUF", # Ruff's own rules
87+
]
88+
89+
ignore = [
90+
"ANN101", # missing type annotation for self in method
91+
"ANN102", # missing type annotation for cls in classmethod
92+
"SIM105", # I don't like contextlib.suppress
93+
"UP038", # astral-sh/ruff#7871
94+
]

setup.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import ast
22
import os
3-
from pathlib import Path
43
import re
4+
from pathlib import Path
55
from typing import Iterable
6-
from setuptools import setup
76

7+
from setuptools import setup
88

99
current_dir = Path(__file__).parent.resolve()
1010
ts_client_dir = current_dir / "typeshed_client"
@@ -46,7 +46,7 @@ def find_bundled_files() -> Iterable[str]:
4646
},
4747
license="MIT",
4848
packages=["typeshed_client"],
49-
install_requires=["importlib_resources >= 1.4.0"],
49+
install_requires=["importlib_resources >= 1.4.0", "typing-extensions>=4.5.0"],
5050
package_data={"typeshed_client": list(find_bundled_files())},
5151
classifiers=[
5252
"Development Status :: 3 - Alpha",

tests/test.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
from pathlib import Path
21
import ast
2+
import unittest
3+
from pathlib import Path
4+
from typing import Any, Optional, Set, Type
5+
from unittest import mock
6+
37
import typeshed_client
48
from typeshed_client.finder import (
5-
get_search_context,
9+
ModulePath,
610
PythonVersion,
7-
get_stub_file,
811
SearchContext,
9-
ModulePath,
12+
get_search_context,
13+
get_stub_file,
1014
)
1115
from typeshed_client.parser import get_stub_names
12-
from typing import Any, Set, Type, Optional
13-
from unittest import mock
14-
import unittest
1516

1617
TEST_TYPESHED = Path(__file__).parent / "typeshed"
1718
PACKAGES = Path(__file__).parent / "site-packages"
@@ -334,7 +335,12 @@ def test(self) -> None:
334335
ctx = get_search_context(raise_on_warnings=True)
335336
for module_name, module_path in typeshed_client.get_all_stub_files(ctx):
336337
with self.subTest(path=module_name):
337-
ast = typeshed_client.get_stub_ast(module_name, search_context=ctx)
338+
try:
339+
ast = typeshed_client.get_stub_ast(module_name, search_context=ctx)
340+
except SyntaxError:
341+
# idlelib for some reason ships an example stub file with a syntax error.
342+
# typeshed-client should also throw a SyntaxError in this case.
343+
continue
338344
assert ast is not None
339345
is_init = module_path.name == "__init__.pyi"
340346
typeshed_client.parser.parse_ast(

tox.ini

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ commands =
99

1010
[testenv:black]
1111
deps =
12-
black == 24.1.1
12+
black == 24.2.0
1313
commands =
1414
black --check .
1515

@@ -22,9 +22,8 @@ commands =
2222

2323
[gh-actions]
2424
python =
25-
3.7: py37
2625
3.8: py38
2726
3.9: py39
2827
3.10: py310
29-
3.11: py311, black, mypy
30-
3.12: py312
28+
3.11: py311
29+
3.12: py312, black, mypy

typeshed_client/__init__.py

+16-21
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,41 @@
11
"""Package for retrieving data from typeshed."""
22

3-
from . import finder
4-
from . import parser
5-
from . import resolver
6-
73
# Exported names
84
from .finder import (
9-
get_stub_ast,
10-
get_stub_file,
5+
ModulePath,
6+
SearchContext,
117
get_all_stub_files,
128
get_search_context,
13-
SearchContext,
14-
ModulePath,
9+
get_stub_ast,
10+
get_stub_file,
1511
)
1612
from .parser import (
17-
get_stub_names,
18-
parse_ast,
1913
ImportedName,
2014
NameDict,
2115
NameInfo,
2216
OverloadedName,
17+
get_stub_names,
18+
parse_ast,
2319
)
2420
from .resolver import ImportedInfo, Resolver
2521

26-
2722
__version__ = "2.4.0"
2823

2924

3025
__all__ = [
31-
"__version__",
32-
"get_stub_ast",
33-
"get_stub_file",
34-
"get_all_stub_files",
35-
"get_search_context",
36-
"SearchContext",
37-
"ModulePath",
38-
"get_stub_names",
39-
"parse_ast",
26+
"ImportedInfo",
4027
"ImportedName",
28+
"ModulePath",
4129
"NameDict",
4230
"NameInfo",
4331
"OverloadedName",
44-
"ImportedInfo",
4532
"Resolver",
33+
"SearchContext",
34+
"__version__",
35+
"get_all_stub_files",
36+
"get_search_context",
37+
"get_stub_ast",
38+
"get_stub_file",
39+
"get_stub_names",
40+
"parse_ast",
4641
]

0 commit comments

Comments
 (0)