From 7649f6e6b5075fe2ecd205b92710025d5bb9c74f Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 25 May 2024 08:23:43 -0400 Subject: [PATCH 01/15] sponsors: add Klaviyo --- README.md | 1 + docs/_static/sponsors/Klaviyo.svg | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 docs/_static/sponsors/Klaviyo.svg diff --git a/README.md b/README.md index d22340332..c3a837262 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Especially those generously supporting us at the *The Organization* tier and hig

+

diff --git a/docs/_static/sponsors/Klaviyo.svg b/docs/_static/sponsors/Klaviyo.svg new file mode 100644 index 000000000..67125290c --- /dev/null +++ b/docs/_static/sponsors/Klaviyo.svg @@ -0,0 +1,6 @@ + + + + + + From f62496120f63b33225ff25d5e3b686cf18233685 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 25 May 2024 08:33:19 -0400 Subject: [PATCH 02/15] pre-commit autoupdate --- .github/CODE_OF_CONDUCT.md | 2 +- .pre-commit-config.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md index 1d8ad1833..348412b12 100644 --- a/.github/CODE_OF_CONDUCT.md +++ b/.github/CODE_OF_CONDUCT.md @@ -6,7 +6,7 @@ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender -identity and expression, level of experience, education, socio-economic status, +identity and expression, level of experience, education, socioeconomic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation. diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ecc044f99..1d58a0d58 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.3 + rev: v0.4.5 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] @@ -21,7 +21,7 @@ repos: args: [tests] - repo: https://github.com/codespell-project/codespell - rev: v2.2.6 + rev: v2.3.0 hooks: - id: codespell args: [--exclude-file=tests/test_mypy.yml] From 1a7b87daaeaef75414fcd1c074d1cc64453ba80c Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sun, 26 May 2024 20:33:24 +0200 Subject: [PATCH 03/15] Add white background --- docs/_static/sponsors/Klaviyo.svg | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/docs/_static/sponsors/Klaviyo.svg b/docs/_static/sponsors/Klaviyo.svg index 67125290c..2acdcac6e 100644 --- a/docs/_static/sponsors/Klaviyo.svg +++ b/docs/_static/sponsors/Klaviyo.svg @@ -1,6 +1 @@ - - - - - - + From bccbcad65d9fc321523a607e7c7a81ff7e93ba0d Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sun, 26 May 2024 20:42:38 +0200 Subject: [PATCH 04/15] Leave some breathing room --- docs/_static/sponsors/Klaviyo.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_static/sponsors/Klaviyo.svg b/docs/_static/sponsors/Klaviyo.svg index 2acdcac6e..4fcc6d8c6 100644 --- a/docs/_static/sponsors/Klaviyo.svg +++ b/docs/_static/sponsors/Klaviyo.svg @@ -1 +1 @@ - + From e976ebcac8c54c3b1c47986d7db253ad9653cccd Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sun, 26 May 2024 20:56:27 +0200 Subject: [PATCH 05/15] Fix ratio --- docs/_static/sponsors/Klaviyo.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_static/sponsors/Klaviyo.svg b/docs/_static/sponsors/Klaviyo.svg index 4fcc6d8c6..f73b04d49 100644 --- a/docs/_static/sponsors/Klaviyo.svg +++ b/docs/_static/sponsors/Klaviyo.svg @@ -1 +1 @@ - + From 6f99945f40b7bea2bea8ae2198d38508f960034a Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sun, 26 May 2024 21:00:49 +0200 Subject: [PATCH 06/15] Actual white --- docs/_static/sponsors/Klaviyo.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_static/sponsors/Klaviyo.svg b/docs/_static/sponsors/Klaviyo.svg index f73b04d49..6c7449bc7 100644 --- a/docs/_static/sponsors/Klaviyo.svg +++ b/docs/_static/sponsors/Klaviyo.svg @@ -1 +1 @@ - + From 5618e6fb8d8c45071b9b938fd42afad7f53c1a0f Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Mon, 27 May 2024 20:07:17 +0200 Subject: [PATCH 07/15] Add missing empty lines to changelog btw releases --- CHANGELOG.md | 2 ++ changelog.d/towncrier_template.md.jinja | 1 + 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 237a36ec6..3dee3acac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ See https://github.com/python-attrs/attrs/blob/main/.github/CONTRIBUTING.md#chan + ## [23.2.0](https://github.com/python-attrs/attrs/tree/23.2.0) - 2023-12-31 ### Changes @@ -42,6 +43,7 @@ See https://github.com/python-attrs/attrs/blob/main/.github/CONTRIBUTING.md#chan It is, for example, now possible to attach methods. [#1203](https://github.com/python-attrs/attrs/issues/1203) + ## [23.1.0](https://github.com/python-attrs/attrs/tree/23.1.0) - 2023-04-16 ### Backwards-incompatible Changes diff --git a/changelog.d/towncrier_template.md.jinja b/changelog.d/towncrier_template.md.jinja index d9ae7c10e..d07a85984 100644 --- a/changelog.d/towncrier_template.md.jinja +++ b/changelog.d/towncrier_template.md.jinja @@ -25,4 +25,5 @@ No significant changes. {% endif %} + {% endfor %} From b393d79aafbf4ee58740f19dd4ad28ed29f3205c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 17:50:00 -0400 Subject: [PATCH 08/15] [pre-commit.ci] pre-commit autoupdate (#1292) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.5 → v0.4.7](https://github.com/astral-sh/ruff-pre-commit/compare/v0.4.5...v0.4.7) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1d58a0d58..cd9cf25c6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.5 + rev: v0.4.7 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] From e1b2c9491bd7d73e6049d8ad54828cc785577103 Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Wed, 26 Jun 2024 14:25:39 +0200 Subject: [PATCH 09/15] refactor: Only loop once on "cached_properties" when building slotted classes (#1290) Only loop once on "cached_properties" when building slotted classes Previously the cached_properties dict was read three times. Co-authored-by: Hynek Schlawack --- src/attr/_make.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/attr/_make.py b/src/attr/_make.py index d3bfb440f..d1c08dea4 100644 --- a/src/attr/_make.py +++ b/src/attr/_make.py @@ -931,19 +931,13 @@ def _create_slots_class(self): # To know to update them. additional_closure_functions_to_update = [] if cached_properties: - # Add cached properties to names for slotting. - names += tuple(cached_properties.keys()) - - for name in cached_properties: - # Clear out function from class to avoid clashing. - del cd[name] - - additional_closure_functions_to_update.extend( - cached_properties.values() - ) - class_annotations = _get_annotations(self._cls) for name, func in cached_properties.items(): + # Add cached properties to names for slotting. + names += (name,) + # Clear out function from class to avoid clashing. + del cd[name] + additional_closure_functions_to_update.append(func) annotation = inspect.signature(func).return_annotation if annotation is not inspect.Parameter.empty: class_annotations[name] = annotation From 11288d5709da70d123951663570d380838cd1c1a Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Fri, 28 Jun 2024 09:41:56 +0200 Subject: [PATCH 10/15] Update Ruff --- .pre-commit-config.yaml | 2 +- tests/test_annotations.py | 23 +++++++++++++---------- tests/test_make.py | 2 +- tests/test_next_gen.py | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cd9cf25c6..be1ec5962 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.7 + rev: v0.5.0 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/tests/test_annotations.py b/tests/test_annotations.py index d27d9e374..516c53ff7 100644 --- a/tests/test_annotations.py +++ b/tests/test_annotations.py @@ -120,15 +120,15 @@ class C: attr.resolve_types(C) - assert int == attr.fields(C).a.type + assert int is attr.fields(C).a.type assert attr.Factory(list) == attr.fields(C).x.default - assert typing.List[int] == attr.fields(C).x.type + assert typing.List[int] is attr.fields(C).x.type - assert int == attr.fields(C).y.type + assert int is attr.fields(C).y.type assert 2 == attr.fields(C).y.default - assert int == attr.fields(C).z.type + assert int is attr.fields(C).z.type assert typing.Any == attr.fields(C).foo.type @@ -534,7 +534,7 @@ class C: attr.resolve_types(C, globals) - assert attr.fields(C).x.type == Annotated[float, "test"] + assert Annotated[float, "test"] is attr.fields(C).x.type @attr.define class D: @@ -542,7 +542,7 @@ class D: attr.resolve_types(D, globals, include_extras=False) - assert attr.fields(D).x.type == float + assert float is attr.fields(D).x.type def test_resolve_types_auto_attrib(self, slots): """ @@ -658,8 +658,8 @@ class B(A): attr.resolve_types(A) attr.resolve_types(B) - assert int == attr.fields(A).n.type - assert int == attr.fields(B).n.type + assert int is attr.fields(A).n.type + assert int is attr.fields(B).n.type def test_resolve_twice(self): """ @@ -672,9 +672,12 @@ class A: n: "int" attr.resolve_types(A) - assert int == attr.fields(A).n.type + + assert int is attr.fields(A).n.type + attr.resolve_types(A) - assert int == attr.fields(A).n.type + + assert int is attr.fields(A).n.type @pytest.mark.parametrize( diff --git a/tests/test_make.py b/tests/test_make.py index 736ab8cf9..a5490f9e5 100644 --- a/tests/test_make.py +++ b/tests/test_make.py @@ -1099,7 +1099,7 @@ class D: cls = make_class("C", {}) - assert cls.__mro__[-1] == object + assert cls.__mro__[-1] is object cls = make_class("C", {}, bases=(D,)) diff --git a/tests/test_next_gen.py b/tests/test_next_gen.py index 7d053d214..a46183e0c 100644 --- a/tests/test_next_gen.py +++ b/tests/test_next_gen.py @@ -36,7 +36,7 @@ def test_field_type(self): A = attrs.make_class("A", classFields) - assert int == attrs.fields(A).testint.type + assert int is attrs.fields(A).testint.type def test_no_slots(self): """ From 3bec9e18252c2c0b331b16414c25b57684c64b4c Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Thu, 11 Jul 2024 12:17:22 +0200 Subject: [PATCH 11/15] Add Codspeed (#1299) * Add Codspeed * Only run benchmarks on 3.12 (for now?) --- .github/workflows/ci.yml | 7 +++++++ pyproject.toml | 1 + tests/test_functional.py | 1 + tox.ini | 7 ++++++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2e9bb893..76c774d0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,6 +77,13 @@ jobs: path: .coverage.* if-no-files-found: ignore + - name: Run CodSpeed benchmarks + uses: CodSpeedHQ/action@v2 + with: + token: ${{ secrets.CODSPEED_TOKEN }} + run: tox run -e codspeed + if: matrix.python-version == '3.12' + coverage: name: Combine & check coverage. runs-on: ubuntu-latest diff --git a/pyproject.toml b/pyproject.toml index 80962a931..424a2d036 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,7 @@ tests = [ "pympler", # 4.3.0 dropped last use of `convert` "pytest>=4.3.0", + "pytest-codspeed", "pytest-xdist[psutil]", "attrs[tests-mypy]", ] diff --git a/tests/test_functional.py b/tests/test_functional.py index 341ee50a8..141b6b586 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -106,6 +106,7 @@ class WithMetaSlots(metaclass=Meta): FromMakeClass = attr.make_class("FromMakeClass", ["x"]) +@pytest.mark.benchmark() class TestFunctional: """ Functional tests. diff --git a/tox.ini b/tox.ini index e2b549dae..84c4d3926 100644 --- a/tox.ini +++ b/tox.ini @@ -36,7 +36,6 @@ set_env = commands_pre = python -c 'import pathlib; pathlib.Path("{env_site_packages_dir}/cov.pth").write_text("import coverage; coverage.process_startup()")' commands = coverage run -m pytest {posargs:-n auto} - [testenv:coverage-report] # Keep base_python in-sync with .python-version-default base_python = py312 @@ -49,6 +48,12 @@ commands = coverage report +[testenv:codspeed] +extras = tests +pass_env = CODSPEED_TOKEN +commands = pytest --codspeed + + [testenv:docs] # Keep base_python in-sync with ci.yml/docs and .readthedocs.yaml. base_python = py312 From 0e031fc83c64ca87581158efd8036fb9cd804f22 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Thu, 11 Jul 2024 12:26:33 +0200 Subject: [PATCH 12/15] CodSpeed needs more ENV --- .github/workflows/ci.yml | 2 +- tox.ini | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76c774d0b..75a0c81de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -81,7 +81,7 @@ jobs: uses: CodSpeedHQ/action@v2 with: token: ${{ secrets.CODSPEED_TOKEN }} - run: tox run -e codspeed + run: pytest --codspeed if: matrix.python-version == '3.12' coverage: diff --git a/tox.ini b/tox.ini index 84c4d3926..e2dd63e43 100644 --- a/tox.ini +++ b/tox.ini @@ -48,12 +48,6 @@ commands = coverage report -[testenv:codspeed] -extras = tests -pass_env = CODSPEED_TOKEN -commands = pytest --codspeed - - [testenv:docs] # Keep base_python in-sync with ci.yml/docs and .readthedocs.yaml. base_python = py312 From 6f64cd6d1928c834f840f592eadb8efd1d31cedb Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Thu, 11 Jul 2024 13:24:51 +0200 Subject: [PATCH 13/15] Cooperate on making CodSpeed work in tox (#1300) * Cooperate on making CodSpeed work in tox * Make CodSpeed an own job * Install tox * Limit benchmarks 7 Minutes are a bit long * Still too many --- .github/workflows/ci.yml | 26 +++++++++++++++++++------- tests/test_functional.py | 7 ++++++- tox.ini | 11 +++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75a0c81de..e98d52f87 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -77,13 +77,6 @@ jobs: path: .coverage.* if-no-files-found: ignore - - name: Run CodSpeed benchmarks - uses: CodSpeedHQ/action@v2 - with: - token: ${{ secrets.CODSPEED_TOKEN }} - run: pytest --codspeed - if: matrix.python-version == '3.12' - coverage: name: Combine & check coverage. runs-on: ubuntu-latest @@ -122,6 +115,25 @@ jobs: path: htmlcov if: ${{ failure() }} + + codspeed: + name: Run CodSpeed benchmarks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version-file: .python-version-default + cache: pip + - run: python -Im pip install tox-uv + + - name: Run CodSpeed benchmarks + uses: CodSpeedHQ/action@v2 + with: + token: ${{ secrets.CODSPEED_TOKEN }} + run: tox run -e codspeed + + docs: name: Build docs & run doctests runs-on: ubuntu-latest diff --git a/tests/test_functional.py b/tests/test_functional.py index 141b6b586..d4feb6e67 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -106,12 +106,12 @@ class WithMetaSlots(metaclass=Meta): FromMakeClass = attr.make_class("FromMakeClass", ["x"]) -@pytest.mark.benchmark() class TestFunctional: """ Functional tests. """ + @pytest.mark.benchmark() @pytest.mark.parametrize("cls", [C2, C2Slots]) def test_fields(self, cls): """ @@ -146,6 +146,7 @@ def test_fields(self, cls): ), ) == attr.fields(cls) + @pytest.mark.benchmark() @pytest.mark.parametrize("cls", [C1, C1Slots]) def test_asdict(self, cls): """ @@ -181,6 +182,7 @@ class C3: assert "C3(_x=1)" == repr(C3(x=1)) + @pytest.mark.benchmark() @given(booleans(), booleans()) def test_programmatic(self, slots, frozen): """ @@ -338,6 +340,7 @@ def test_metaclass_preserved(self, cls): """ assert Meta == type(cls) + @pytest.mark.benchmark() def test_default_decorator(self): """ Default decorator sets the default and the respective method gets @@ -541,6 +544,7 @@ class C: assert "itemgetter" == attr.fields(C).itemgetter.name assert "x" == attr.fields(C).x.name + @pytest.mark.benchmark() def test_auto_exc(self, slots, frozen): """ Classes with auto_exc=True have a Exception-style __str__, compare and @@ -735,6 +739,7 @@ class D(C): assert "_setattr('y', y)" in src assert object.__setattr__ != D.__setattr__ + @pytest.mark.benchmark() def test_unsafe_hash(self, slots): """ attr.s(unsafe_hash=True) makes a class hashable. diff --git a/tox.ini b/tox.ini index e2dd63e43..f6c94b4a4 100644 --- a/tox.ini +++ b/tox.ini @@ -48,6 +48,17 @@ commands = coverage report +[testenv:codspeed] +extras = tests +pass_env = + CODSPEED_TOKEN + CODSPEED_ENV + ARCH + PYTHONHASHSEED + PYTHONMALLOC +commands = pytest --codspeed -n auto + + [testenv:docs] # Keep base_python in-sync with ci.yml/docs and .readthedocs.yaml. base_python = py312 From 6e25a0c4f52b1acb5e75af0f5158ae5a59b483e3 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 13 Jul 2024 12:01:09 +0200 Subject: [PATCH 14/15] Unpin/fix Pyright (#1302) * Unpin/fix Pyright Fixes #1278 * Consistency * Remove stale comment * Add explanation why we need experimental features --- pyproject.toml | 5 ++ tests/dataclass_transform_example.py | 1 - tests/test_pyright.py | 70 ++++++++++++---------------- tox.ini | 2 +- 4 files changed, 37 insertions(+), 41 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 424a2d036..c7e5b8be4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -272,3 +272,8 @@ showcontent = true pretty = true disallow_untyped_defs = true check_untyped_defs = true + + +[tool.pyright] +# We need epexrimental features for converters. +enableExperimentalFeatures = true diff --git a/tests/dataclass_transform_example.py b/tests/dataclass_transform_example.py index c65df1402..fb28110e6 100644 --- a/tests/dataclass_transform_example.py +++ b/tests/dataclass_transform_example.py @@ -15,7 +15,6 @@ class Define: @attr.define() class DefineConverter: - # mypy plugin adapts the "int" method signature, pyright does not with_converter: int = attr.field(converter=int) diff --git a/tests/test_pyright.py b/tests/test_pyright.py index 800d6099f..3f2bf89dd 100644 --- a/tests/test_pyright.py +++ b/tests/test_pyright.py @@ -10,8 +10,6 @@ import pytest -import attrs - pytestmark = [ pytest.mark.skipif( @@ -20,21 +18,16 @@ ] -@attrs.frozen -class PyrightDiagnostic: - severity: str - message: str - - -def parse_pyright_output(test_file: Path) -> set[PyrightDiagnostic]: +def parse_pyright_output(test_file: Path) -> set[tuple[str, str]]: pyright = subprocess.run( # noqa: PLW1510 ["pyright", "--outputjson", str(test_file)], capture_output=True ) pyright_result = json.loads(pyright.stdout) + # We use tuples instead of proper classes to get nicer diffs from pytest. return { - PyrightDiagnostic(d["severity"], d["message"]) + (d["severity"], d["message"]) for d in pyright_result["generalDiagnostics"] } @@ -49,41 +42,40 @@ def test_pyright_baseline(): diagnostics = parse_pyright_output(test_file) - # Expected diagnostics as per pyright 1.1.311 expected_diagnostics = { - PyrightDiagnostic( - severity="information", - message='Type of "Define.__init__" is' - ' "(self: Define, a: str, b: int) -> None"', + ( + "information", + 'Type of "Define.__init__" is "(self: Define, a: str, b: int) -> None"', ), - PyrightDiagnostic( - severity="information", - message='Type of "DefineConverter.__init__" is ' + ( + "information", + 'Type of "DefineConverter.__init__" is ' '"(self: DefineConverter, with_converter: str | Buffer | ' 'SupportsInt | SupportsIndex | SupportsTrunc) -> None"', ), - PyrightDiagnostic( - severity="error", - message='Cannot assign member "a" for type ' - '"Frozen"\n\xa0\xa0"Frozen" is frozen\n\xa0\xa0\xa0\xa0Member "__set__" is unknown', + ( + "error", + 'Cannot assign to attribute "a" for class ' + '"Frozen"\n\xa0\xa0"Frozen" is frozen\n\xa0\xa0\xa0\xa0' + 'Attribute "__set__" is unknown', ), - PyrightDiagnostic( - severity="information", - message='Type of "d.a" is "Literal[\'new\']"', + ( + "information", + 'Type of "d.a" is "Literal[\'new\']"', ), - PyrightDiagnostic( - severity="error", - message='Cannot assign member "a" for type ' + ( + "error", + 'Cannot assign to attribute "a" for class ' '"FrozenDefine"\n\xa0\xa0"FrozenDefine" is frozen\n\xa0\xa0\xa0\xa0' - 'Member "__set__" is unknown', + 'Attribute "__set__" is unknown', ), - PyrightDiagnostic( - severity="information", - message='Type of "d2.a" is "Literal[\'new\']"', + ( + "information", + 'Type of "d2.a" is "Literal[\'new\']"', ), - PyrightDiagnostic( - severity="information", - message='Type of "af.__init__" is "(_a: int) -> None"', + ( + "information", + 'Type of "af.__init__" is "(_a: int) -> None"', ), } @@ -110,9 +102,9 @@ def test_pyright_attrsinstance_compat(tmp_path): diagnostics = parse_pyright_output(test_pyright_attrsinstance_compat_path) expected_diagnostics = { - PyrightDiagnostic( - severity="information", - message='Type of "attrs.AttrsInstance" is "type[AttrsInstance]"', - ), + ( + "information", + 'Type of "attrs.AttrsInstance" is "type[AttrsInstance]"', + ) } assert diagnostics == expected_diagnostics diff --git a/tox.ini b/tox.ini index f6c94b4a4..cafb068fa 100644 --- a/tox.ini +++ b/tox.ini @@ -102,7 +102,7 @@ commands = towncrier build --version main --draft [testenv:pyright] extras = tests -deps = pyright<1.1.359 +deps = pyright commands = pytest tests/test_pyright.py -vv From 0b07265e0cd8081e30027c0e8c7dc8ea57b25167 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 13 Jul 2024 12:33:59 +0200 Subject: [PATCH 15/15] Unpin Mypy (#1301) * Unpin Mypy fixes #1279 Looks like 1.10.1 fixed itself? * Fix type errors * Update pins * Don't run Mypy on 3.8 too * wtf * Fix order --- .github/workflows/ci.yml | 16 ++++++++++++---- pyproject.toml | 4 ++-- tests/test_mypy.yml | 8 ++++---- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e98d52f87..ead381913 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,16 +49,24 @@ jobs: - name: Prepare tox run: | V=${{ matrix.python-version }} + DO_MYPY=1 if [[ "$V" = pypy-* ]]; then + DO_MYPY=0 + V=pypy3 - IS_PYPY=1 else + if [[ "$V" == "3.7" || "$V" == "3.8" ]]; then + DO_MYPY=0 + echo "skipping $V" + else + echo "not skipping $V" + fi + V=py$(echo $V | tr -d .) - IS_PYPY=0 fi - echo IS_PYPY=$IS_PYPY >>$GITHUB_ENV + echo DO_MYPY=$DO_MYPY >>$GITHUB_ENV echo TOX_PYTHON=$V >>$GITHUB_ENV python -Im pip install tox @@ -68,7 +76,7 @@ jobs: - run: python -Im tox run -e ${{ env.TOX_PYTHON }}-tests - run: python -Im tox run -e ${{ env.TOX_PYTHON }}-mypy - if: env.IS_PYPY == '0' && matrix.python-version != '3.7' + if: env.DO_MYPY == '1' - name: Upload coverage data uses: actions/upload-artifact@v4 diff --git a/pyproject.toml b/pyproject.toml index c7e5b8be4..933bd9d0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,10 +31,10 @@ dynamic = ["version", "readme"] [project.optional-dependencies] tests-mypy = [ - 'pytest-mypy-plugins; platform_python_implementation == "CPython" and python_version >= "3.8" and python_version < "3.13"', + 'pytest-mypy-plugins; platform_python_implementation == "CPython" and python_version >= "3.9" and python_version < "3.13"', # Since the mypy error messages keep changing, we have to keep updating this # pin. - 'mypy>=1.6,<1.10; platform_python_implementation == "CPython" and python_version >= "3.8"', + 'mypy>=1.10.1; platform_python_implementation == "CPython" and python_version >= "3.9"', ] tests = [ # For regression test to ensure cloudpickle compat doesn't break. diff --git a/tests/test_mypy.yml b/tests/test_mypy.yml index 0d0757233..1a0a366e5 100644 --- a/tests/test_mypy.yml +++ b/tests/test_mypy.yml @@ -589,7 +589,7 @@ x: Optional[T] @classmethod def clsmeth(cls) -> None: - reveal_type(cls) # N: Revealed type is "Type[main.A[T`1]]" + reveal_type(cls) # N: Revealed type is "type[main.A[T`1]]" - case: testAttrsForwardReference main: | @@ -645,7 +645,7 @@ b: str = attr.ib() @classmethod def new(cls) -> A: - reveal_type(cls) # N: Revealed type is "Type[main.A]" + reveal_type(cls) # N: Revealed type is "type[main.A]" return cls(6, 'hello') @classmethod def bad(cls) -> A: @@ -680,7 +680,7 @@ @classmethod def foo(cls, x: Union[int, str]) -> Union[int, str]: - reveal_type(cls) # N: Revealed type is "Type[main.A]" + reveal_type(cls) # N: Revealed type is "type[main.A]" reveal_type(cls.other()) # N: Revealed type is "builtins.str" return x @@ -1411,4 +1411,4 @@ reveal_type(A) # N: Revealed type is "def () -> main.A" if has(A): - reveal_type(A) # N: Revealed type is "Type[attr.AttrsInstance]" + reveal_type(A) # N: Revealed type is "type[attr.AttrsInstance]"