Skip to content

Commit 3c1de4f

Browse files
Makes classes compatible with mypy 1.2
1 parent 1d9d5c9 commit 3c1de4f

36 files changed

+1312
-1122
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ jobs:
3838
- name: Run tests
3939
run: |
4040
poetry run flake8 .
41-
poetry run mypy classes ./tests/**/*.py
41+
# TODO: Remove `no-warn-unused-ignores` flag once we drop support for Python 3.7 and 3.8
42+
poetry run mypy --no-warn-unused-ignores classes ./tests/**/*.py
4243
poetry run codespell classes tests docs typesafety README.md CONTRIBUTING.md CHANGELOG.md
4344
poetry run pytest classes tests docs/pages README.md
4445
poetry run doc8 -q docs

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
We follow Semantic Versions since the `0.1.0` release.
44

5+
## Version 0.5.0 WIP
6+
7+
### Features
8+
9+
- Now requires `mypy>=1.2`
510

611
## Version 0.4.1
712

classes/_typeclass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def __call__(
379379
],
380380
*args,
381381
**kwargs,
382-
) -> _ReturnType:
382+
) -> _ReturnType: # type: ignore[type-var]
383383
"""
384384
We use this method to actually call a typeclass.
385385

classes/contrib/mypy/typeops/call_signatures.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from mypy.typeops import get_type_vars, make_simplified_union
77
from mypy.types import CallableType, Instance, ProperType
88
from mypy.types import Type as MypyType
9-
from mypy.types import TypeVarType, union_items
9+
from mypy.types import TypeVarType
1010
from typing_extensions import Final, final
1111

12-
from classes.contrib.mypy.typeops import type_loader
12+
from classes.contrib.mypy.typeops import type_loader, union
1313

1414
_INCOMPATIBLE_TYPEVAR_MSG: Final = (
1515
'Argument 1 to {0} has incompatible type "{1}"; expected "{2}"'
@@ -61,7 +61,7 @@ def _infer_type_var(
6161
first_arg: TypeVarType,
6262
passed_type: MypyType,
6363
) -> CallableType:
64-
instance_types = union_items(self._instance_type)
64+
instance_types = union.union_items(self._instance_type)
6565
if isinstance(self._associated_type, Instance):
6666
instance_types.append(_load_supports_type(
6767
first_arg,

classes/contrib/mypy/typeops/mro.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from mypy.subtypes import is_equivalent
55
from mypy.types import Instance
66
from mypy.types import Type as MypyType
7-
from mypy.types import UnionType, union_items
7+
from mypy.types import UnionType
88
from typing_extensions import final
99

10-
from classes.contrib.mypy.typeops import type_loader
10+
from classes.contrib.mypy.typeops import type_loader, union
1111

1212

1313
@final
@@ -78,7 +78,7 @@ def __init__(
7878
"""
7979
self._associated_type = associated_type
8080
self._ctx = ctx
81-
self._instance_types = union_items(instance_type)
81+
self._instance_types = union.union_items(instance_type)
8282

8383
# Why do we store added types in a mutable global state?
8484
# Because, these types are hard to replicate without the proper context.
@@ -181,7 +181,7 @@ def _remove_unified_type(
181181
base = instance_type.type.bases[index]
182182
union_types = [
183183
type_arg
184-
for type_arg in union_items(base.args[0])
184+
for type_arg in union.union_items(base.args[0])
185185
if type_arg not in supports_type.args
186186
]
187187
instance_type.type.bases[index] = supports_type.copy_modified(

classes/contrib/mypy/typeops/type_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def load_supports_type(
2323
[arg_type],
2424
)
2525
assert supports_spec
26-
supports_spec.type._promote = None # noqa: WPS437
26+
supports_spec.type._promote = [] # noqa: WPS437
2727
return supports_spec
2828

2929

classes/contrib/mypy/typeops/union.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import List
2+
3+
from mypy.types import ProperType
4+
from mypy.types import Type as MypyType
5+
from mypy.types import flatten_nested_unions, get_proper_type
6+
7+
8+
def union_items(typ: MypyType) -> List[ProperType]:
9+
"""Get and flat all union types."""
10+
return [
11+
get_proper_type(union_member)
12+
for union_member in flatten_nested_unions([typ])
13+
]

classes/contrib/mypy/validation/validate_instance/validate_runtime.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
from mypy.erasetype import erase_type
44
from mypy.plugin import MethodContext
5-
from mypy.sametypes import is_same_type
6-
from mypy.subtypes import is_subtype
5+
from mypy.subtypes import is_same_type, is_subtype
76
from mypy.types import Instance
87
from mypy.types import Type as MypyType
98
from mypy.types import TypedDictType

poetry.lock

Lines changed: 1113 additions & 953 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ python = "^3.7"
4848
typing_extensions = ">=3.10,<5.0"
4949

5050
[tool.poetry.dev-dependencies]
51-
mypy = "^0.942"
51+
mypy = "^1.2.0"
5252

5353
wemake-python-styleguide = "^0.17"
5454
flake8-pytest-style = "^1.6"
55-
nitpick = "^0.32"
55+
nitpick = "^0.33.1"
5656

5757
safety = "^2.3"
5858

5959
pytest = "^7.2"
6060
pytest-cov = "^4.0"
6161
pytest-randomly = "^3.12"
62-
pytest-mypy-plugins = "^1.9"
62+
pytest-mypy-plugins = "^1.10.1"
6363

6464
sphinx = "^5.2"
6565
sphinx-autodoc-typehints = "^1.20"

0 commit comments

Comments
 (0)