Skip to content

Commit f0a6c2c

Browse files
committedFeb 3, 2023
⬆️ bump dependencies, add py311 support
1 parent df352b8 commit f0a6c2c

10 files changed

+127
-124
lines changed
 

‎.github/PULL_REQUEST_TEMPLATE.md

+5
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ to make sure you didn't miss anything.
1010
- [ ] Tests added
1111
- [ ] Build OK
1212
- [ ] Added changelog entry (section 'next release')
13+
- [ ] Bumped version in `pyproject.toml`
14+
- [ ] Merge PR
15+
- [ ] Delete branch
16+
- [ ] Add tag
17+
- [ ] Publish to PyPI

‎.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
python-version: ["3.7", "3.8", "3.9", "3.10"]
17+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
1818

1919
steps:
2020
- uses: actions/checkout@v1
@@ -25,6 +25,6 @@ jobs:
2525
- name: Install dependencies
2626
run: |
2727
python -m pip install --upgrade pip
28-
pip install tox tox-gh-actions poetry==1.2.2
28+
pip install tox tox-gh-actions poetry==1.3.2
2929
- name: Test with tox
3030
run: tox

‎CHANGELOG.rst

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ Changelog
44
Next release
55
------------
66

7+
1.0.0 (2023-02-03)
8+
------------------
9+
10+
- 🦺 First 1.x release. Semantic versioning will be used to
11+
indicate potential breaking changes in the future.
12+
- 🐍 Add official Python 3.11 support.
13+
- 👌 Simplify name of mypy plugin from ``quacks.mypy`` to ``quacks``.
14+
The old name is still accessible for backwards compatibility.
15+
716
0.2.0 (2022-01-04)
817
------------------
918

‎README.rst

+1-38
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ your `mypy config file <https://mypy.readthedocs.io/en/latest/config_file.html>`
4141
.. code-block:: ini
4242
4343
[mypy]
44-
plugins = quacks.mypy
44+
plugins = quacks
4545
4646
Features
4747
--------
@@ -76,40 +76,3 @@ reducing readability:
7676
def name(self) -> str: ...
7777
@property
7878
def is_premium(self) -> bool: ...
79-
80-
Partial protocols (work in progress)
81-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82-
83-
What if you want to reuse parts of a protocol?
84-
Imagine we have several functions who use various properties of ``User``.
85-
With partial protocols you can reuse attributes without having to define
86-
many overlapping protocols.
87-
Inspired by `clojure spec <https://youtu.be/YR5WdGrpoug?t=1971>`_.
88-
89-
(exact syntax TBD)
90-
91-
.. code-block:: python
92-
93-
class User(Protocol):
94-
id: int
95-
name: str
96-
is_premium: bool
97-
address: Address
98-
99-
class Address(Protocol):
100-
street: str
101-
city: str
102-
country: str
103-
104-
from quacks import _
105-
106-
def determine_discount(u: User[_.id.is_premium]) -> int:
107-
... # access `id` and `is_premium` attributes
108-
109-
def greet(u: User[_.name.address[_.country]]) -> None:
110-
... # access `name` and `address.country` attributes
111-
112-
u: User = ...
113-
114-
determine_discount(u)
115-
greet(u)

‎mypy.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ warn_unused_ignores = true
1111
warn_no_return = true
1212
warn_unreachable = true
1313
warn_return_any = true
14-
plugins = quacks.mypy
14+
plugins = quacks
1515

1616
[mypy-tests.*]
1717
disallow_untyped_defs = false

‎poetry.lock

+88-74
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pyproject.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "quacks"
3-
version = "0.2.0"
3+
version = "1.0.0"
44
description = "Better duck-typing with mypy-compatible extensions to Protocol"
55
authors = ["Arie Bovenberg <a.c.bovenberg@gmail.com>"]
66
license = "MIT"
@@ -23,6 +23,7 @@ classifiers = [
2323
"Programming Language :: Python :: 3.8",
2424
"Programming Language :: Python :: 3.9",
2525
"Programming Language :: Python :: 3.10",
26+
"Programming Language :: Python :: 3.11",
2627
]
2728

2829
[tool.poetry.dependencies]
@@ -32,7 +33,7 @@ typing-extensions = ">3.7,<5"
3233

3334
[tool.poetry.dev-dependencies]
3435
pytest = "^7.2.0"
35-
black = "^22.10"
36+
black = "^23.1.0"
3637
mypy = "^0.991"
3738
pytest-mypy-plugins = "^1.10.1"
3839
isort = "^5.11.5"

‎src/quacks/__init__.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import _GenericAlias # type: ignore
2-
from typing import ClassVar
2+
from typing import TYPE_CHECKING, ClassVar
33

44
from typing_extensions import Protocol
55

@@ -14,6 +14,20 @@
1414
__all__ = ["readonly"]
1515

1616

17+
# The logic below allows the mypy plugin to be exposed at root level,
18+
# while also ensuring:
19+
# - mypy doesn't become a runtime dependency
20+
# - mypy itself is not scanned during type checking
21+
if not TYPE_CHECKING: # pragma: no cover
22+
23+
def __getattr__(name):
24+
if name == "plugin":
25+
from .mypy import plugin
26+
27+
return plugin
28+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
29+
30+
1731
def readonly(cls: type) -> type:
1832
"""Decorate a :class:`~typing.Protocol` to make it read-only.
1933

‎tests/test_readonly.py

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class C: # type: ignore
2626

2727

2828
def test_protocol_implementation_not_accepted():
29-
3029
with pytest.raises(TypeError, match="Protocol"):
3130

3231
class A(Protocol):

‎tox.ini

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
isolated_build = true
3-
envlist = py{37,38,39,310},lint,docs,minimal,isort
3+
envlist = py{37,38,39,310,311},lint,docs,isort
44
[testenv]
55
allowlist_externals =
66
poetry
@@ -10,18 +10,15 @@ commands =
1010
poetry run pytest {posargs}
1111

1212
[testenv:lint]
13-
basepython=python3.9
1413
commands=
1514
poetry run black --check --diff src/ tests/
1615
poetry run flake8 src/ tests/
1716

1817
[testenv:isort]
19-
basepython=python3.9
2018
commands=
2119
poetry run isort --check-only --diff src/ tests/
2220

2321
[testenv:docs]
24-
basepython=python3.9
2522
commands_pre=pip install .
2623
deps=
2724
-rdocs/requirements.txt
@@ -44,5 +41,6 @@ exclude_lines=
4441
python =
4542
3.7: py37
4643
3.8: py38
47-
3.9: py39, lint, isort, docs
44+
3.9: py39
4845
3.10: py310
46+
3.11: py311, lint, isort, docs

0 commit comments

Comments
 (0)
Please sign in to comment.