Skip to content

Commit 116ddd7

Browse files
authored
Merge branch 'master' into master
2 parents d3029ae + 46c108e commit 116ddd7

File tree

5 files changed

+73
-19
lines changed

5 files changed

+73
-19
lines changed

.github/workflows/test.yml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ jobs:
7070
toxenv: py
7171
tox_extra_args: "-n 4"
7272
test_mypyc: true
73-
7473
- name: Test suite with py313-ubuntu, mypyc-compiled
7574
python: '3.13'
7675
arch: x64
7776
os: ubuntu-latest
7877
toxenv: py
7978
tox_extra_args: "-n 4"
8079
test_mypyc: true
80+
8181
# - name: Test suite with py314-dev-ubuntu
8282
# python: '3.14-dev'
8383
# arch: x64
@@ -94,13 +94,16 @@ jobs:
9494
os: macos-13
9595
toxenv: py
9696
tox_extra_args: "-n 3 mypyc/test/test_run.py mypyc/test/test_external.py"
97-
- name: mypyc runtime tests with py38-debug-build-ubuntu
98-
python: '3.8.17'
99-
arch: x64
100-
os: ubuntu-latest
101-
toxenv: py
102-
tox_extra_args: "-n 4 mypyc/test/test_run.py mypyc/test/test_external.py"
103-
debug_build: true
97+
# This is broken. See
98+
# - https://github.com/python/mypy/issues/17819
99+
# - https://github.com/python/mypy/pull/17822
100+
# - name: mypyc runtime tests with py38-debug-build-ubuntu
101+
# python: '3.8.17'
102+
# arch: x64
103+
# os: ubuntu-latest
104+
# toxenv: py
105+
# tox_extra_args: "-n 4 mypyc/test/test_run.py mypyc/test/test_external.py"
106+
# debug_build: true
104107

105108
- name: Type check our own code (py38-ubuntu)
106109
python: '3.8'
@@ -148,17 +151,17 @@ jobs:
148151
./misc/build-debug-python.sh $PYTHONVERSION $PYTHONDIR $VENV
149152
# TODO: does this do anything? env vars aren't passed to the next step right
150153
source $VENV/bin/activate
151-
- name: Latest Dev build
154+
- name: Latest dev build
152155
if: ${{ endsWith(matrix.python, '-dev') }}
153156
run: |
154-
sudo apt-get update
155-
sudo apt-get install -y --no-install-recommends \
156-
build-essential gdb lcov libbz2-dev libffi-dev libgdbm-dev liblzma-dev libncurses5-dev \
157-
libreadline6-dev libsqlite3-dev libssl-dev lzma lzma-dev tk-dev uuid-dev zlib1g-dev
158157
git clone --depth 1 https://github.com/python/cpython.git /tmp/cpython --branch $( echo ${{ matrix.python }} | sed 's/-dev//' )
159158
cd /tmp/cpython
160159
echo git rev-parse HEAD; git rev-parse HEAD
161160
git show --no-patch
161+
sudo apt-get update
162+
sudo apt-get install -y --no-install-recommends \
163+
build-essential gdb lcov libbz2-dev libffi-dev libgdbm-dev liblzma-dev libncurses5-dev \
164+
libreadline6-dev libsqlite3-dev libssl-dev lzma lzma-dev tk-dev uuid-dev zlib1g-dev
162165
./configure --prefix=/opt/pythondev
163166
make -j$(nproc)
164167
sudo make install
@@ -190,7 +193,7 @@ jobs:
190193
191194
- name: Setup tox environment
192195
run: |
193-
tox run -e ${{ matrix.toxenv }} --notes
196+
tox run -e ${{ matrix.toxenv }} --notest
194197
- name: Test
195198
run: tox run -e ${{ matrix.toxenv }} --skip-pkg-install -- ${{ matrix.tox_extra_args }}
196199
continue-on-error: ${{ matrix.allow_failure == 'true' }}

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ List of documentation updates:
187187
* Make changelog visible in mypy documentation (quinn-sasha, PR [17742](https://github.com/python/mypy/pull/17742))
188188
* List all incomplete features in `--enable-incomplete-feature` docs (sobolevn, PR [17633](https://github.com/python/mypy/pull/17633))
189189
* Remove the explicit setting of a pygments theme (Pradyun Gedam, PR [17571](https://github.com/python/mypy/pull/17571))
190+
* Document ReadOnly with TypedDict (Jukka Lehtosalo, PR [17905](https://github.com/python/mypy/pull/17905))
191+
* Document TypeIs (Chelsea Durazo, PR [17821](https://github.com/python/mypy/pull/17821))
190192

191193
### Experimental Inline TypedDict Syntax
192194

@@ -250,6 +252,9 @@ This feature was contributed by Ivan Levkivskyi (PR [17457](https://github.com/p
250252
* Fix typechecking for async generators (Danny Yang, PR [17452](https://github.com/python/mypy/pull/17452))
251253
* Fix strict optional handling in attrs plugin (Ivan Levkivskyi, PR [17451](https://github.com/python/mypy/pull/17451))
252254
* Allow mixing ParamSpec and TypeVarTuple in Generic (Ivan Levkivskyi, PR [17450](https://github.com/python/mypy/pull/17450))
255+
* Improvements to `functools.partial` of types (Shantanu, PR [17898](https://github.com/python/mypy/pull/17898))
256+
* Make ReadOnly TypedDict items covariant (Jukka Lehtosalo, PR [17904](https://github.com/python/mypy/pull/17904))
257+
* Fix union callees with `functools.partial` (Jukka Lehtosalo, PR [17903](https://github.com/python/mypy/pull/17903))
253258

254259
### Typeshed Updates
255260

@@ -263,6 +268,7 @@ Thanks to all mypy contributors who contributed to this release:
263268
- Bénédikt Tran
264269
- Brian Schubert
265270
- bzoracler
271+
- Chelsea Durazo
266272
- Danny Yang
267273
- Edgar Ramírez Mondragón
268274
- Eric Mark Martin

mypy/main.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@
2222
from mypy.errors import CompileError
2323
from mypy.find_sources import InvalidSourceList, create_source_list
2424
from mypy.fscache import FileSystemCache
25-
from mypy.modulefinder import BuildSource, FindModuleCache, SearchPaths, get_search_dirs, mypy_path
25+
from mypy.modulefinder import (
26+
BuildSource,
27+
FindModuleCache,
28+
ModuleNotFoundReason,
29+
SearchPaths,
30+
get_search_dirs,
31+
mypy_path,
32+
)
2633
from mypy.options import INCOMPLETE_FEATURES, BuildType, Options
2734
from mypy.split_namespace import SplitNamespace
2835
from mypy.version import __version__
@@ -1413,7 +1420,15 @@ def set_strict_flags() -> None:
14131420
fail(f"Package name '{p}' cannot have a slash in it.", stderr, options)
14141421
p_targets = cache.find_modules_recursive(p)
14151422
if not p_targets:
1416-
fail(f"Can't find package '{p}'", stderr, options)
1423+
reason = cache.find_module(p)
1424+
if reason is ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS:
1425+
fail(
1426+
f"Package '{p}' cannot be type checked due to missing py.typed marker. See https://mypy.readthedocs.io/en/stable/installed_packages.html for more details",
1427+
stderr,
1428+
options,
1429+
)
1430+
else:
1431+
fail(f"Can't find package '{p}'", stderr, options)
14171432
targets.extend(p_targets)
14181433
for m in special_opts.modules:
14191434
targets.append(BuildSource(None, m, None))

mypy/plugins/functools.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
Type,
1919
TypeOfAny,
2020
UnboundType,
21+
UnionType,
2122
get_proper_type,
2223
)
2324

@@ -130,7 +131,19 @@ def partial_new_callback(ctx: mypy.plugin.FunctionContext) -> Type:
130131
if isinstance(get_proper_type(ctx.arg_types[0][0]), Overloaded):
131132
# TODO: handle overloads, just fall back to whatever the non-plugin code does
132133
return ctx.default_return_type
133-
fn_type = ctx.api.extract_callable_type(ctx.arg_types[0][0], ctx=ctx.default_return_type)
134+
return handle_partial_with_callee(ctx, callee=ctx.arg_types[0][0])
135+
136+
137+
def handle_partial_with_callee(ctx: mypy.plugin.FunctionContext, callee: Type) -> Type:
138+
if not isinstance(ctx.api, mypy.checker.TypeChecker): # use internals
139+
return ctx.default_return_type
140+
141+
if isinstance(callee_proper := get_proper_type(callee), UnionType):
142+
return UnionType.make_union(
143+
[handle_partial_with_callee(ctx, item) for item in callee_proper.items]
144+
)
145+
146+
fn_type = ctx.api.extract_callable_type(callee, ctx=ctx.default_return_type)
134147
if fn_type is None:
135148
return ctx.default_return_type
136149

test-data/unit/check-functools.test

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,32 @@ fn1: Union[Callable[[int], int], Callable[[int], int]]
346346
reveal_type(functools.partial(fn1, 2)()) # N: Revealed type is "builtins.int"
347347

348348
fn2: Union[Callable[[int], int], Callable[[int], str]]
349-
reveal_type(functools.partial(fn2, 2)()) # N: Revealed type is "builtins.object"
349+
reveal_type(functools.partial(fn2, 2)()) # N: Revealed type is "Union[builtins.int, builtins.str]"
350350

351351
fn3: Union[Callable[[int], int], str]
352352
reveal_type(functools.partial(fn3, 2)()) # E: "str" not callable \
353-
# E: "Union[Callable[[int], int], str]" not callable \
354353
# N: Revealed type is "builtins.int" \
355354
# E: Argument 1 to "partial" has incompatible type "Union[Callable[[int], int], str]"; expected "Callable[..., int]"
356355
[builtins fixtures/tuple.pyi]
357356

357+
[case testFunctoolsPartialUnionOfTypeAndCallable]
358+
import functools
359+
from typing import Callable, Union, Type
360+
from typing_extensions import TypeAlias
361+
362+
class FooBar:
363+
def __init__(self, arg1: str) -> None:
364+
pass
365+
366+
def f1(t: Union[Type[FooBar], Callable[..., 'FooBar']]) -> None:
367+
val = functools.partial(t)
368+
369+
FooBarFunc: TypeAlias = Callable[..., 'FooBar']
370+
371+
def f2(t: Union[Type[FooBar], FooBarFunc]) -> None:
372+
val = functools.partial(t)
373+
[builtins fixtures/tuple.pyi]
374+
358375
[case testFunctoolsPartialExplicitType]
359376
from functools import partial
360377
from typing import Type, TypeVar, Callable

0 commit comments

Comments
 (0)