Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8a30073
Basic work on TypeNarrower
JelleZijlstra Feb 9, 2024
58e8403
Initial tests (many failing)
JelleZijlstra Feb 9, 2024
c8d2af8
Fewer test failures
JelleZijlstra Feb 10, 2024
f205910
Fix the remaining tests
JelleZijlstra Feb 10, 2024
75c9dec
Did not actually need TypeNarrowerType
JelleZijlstra Feb 10, 2024
4666486
Error for bad narrowing
JelleZijlstra Feb 10, 2024
25a9c79
temp change typeshed
JelleZijlstra Feb 10, 2024
faa4a07
Fixes
JelleZijlstra Feb 10, 2024
c0e0210
Merge branch 'master' into typenarrower
JelleZijlstra Feb 10, 2024
f107e5b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2024
34700bb
doc
JelleZijlstra Feb 10, 2024
065ec92
fix self check
JelleZijlstra Feb 10, 2024
aef3036
like this maybe
JelleZijlstra Feb 10, 2024
4b19c77
Merge remote-tracking branch 'upstream/master' into typenarrower
JelleZijlstra Feb 10, 2024
6b0e749
Fix and add tests
JelleZijlstra Feb 10, 2024
c9e53e6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 10, 2024
909e53c
Use TypeIs
JelleZijlstra Feb 14, 2024
eb88371
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 14, 2024
1b1e368
Apply suggestions from code review
JelleZijlstra Feb 22, 2024
84c69d2
Code review feedback, new test case, fix incorrect constraints
JelleZijlstra Feb 23, 2024
ae294bf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 23, 2024
7fedbcf
Merge remote-tracking branch 'upstream/master' into typenarrower
JelleZijlstra Mar 1, 2024
dbc229d
Rename error code
JelleZijlstra Mar 1, 2024
8b2fb0b
Quote name
JelleZijlstra Mar 1, 2024
816fd1a
unxfail
JelleZijlstra Mar 1, 2024
d6fcc35
add elif test
JelleZijlstra Mar 1, 2024
ef825ce
type context test
JelleZijlstra Mar 1, 2024
d32956d
Add test
JelleZijlstra Mar 1, 2024
a36a16a
Add error code test case
JelleZijlstra Mar 1, 2024
b32ba80
update docs
JelleZijlstra Mar 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Marc Mueller <[email protected]>
  • Loading branch information
JelleZijlstra and cdce8p authored Feb 22, 2024
commit 1b1e368dabbbd8ef7923b5abcf8027a76b05e0fe
4 changes: 2 additions & 2 deletions docs/source/error_code_list2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,10 @@ because there's no way one can import it.

.. _code-type-is-not-subtype:

Check that TypeIs narrows types [type-is-not-subtype]
Check that ``TypeIs`` narrows types [type-is-not-subtype]
-----------------------------------------------------------------

:pep:`742` requires that when a ``TypeIs`` is used, the narrowed
:pep:`742` requires that when ``TypeIs`` is used, the narrowed
type must be a subtype of the original type::

from typing_extensions import TypeIs
Expand Down
2 changes: 1 addition & 1 deletion mypy/subtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def visit_callable_type(self, left: CallableType) -> bool:
# They are not compatible. See https://github.com/python/mypy/issues/11307
return False
elif right.type_is is not None and left.type_is is None:
# Similarly, if one function has typeNarrower and the other does not,
# Similarly, if one function has `TypeIs` and the other does not,
# they are not compatible.
return False
return is_callable_compatible(
Expand Down
3 changes: 1 addition & 2 deletions test-data/unit/check-typeis.test
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ main:5: note: def is_float(self, a: object) -> bool
[case testTypeIsInAnd]
from typing import Any
from typing_extensions import TypeIs
import types
def isclass(a: object) -> bool:
pass
def ismethod(a: object) -> TypeIs[float]:
Expand Down Expand Up @@ -661,7 +660,7 @@ if typeguard(y="42", x=x):

[case testGenericAliasWithTypeIs]
from typing import Callable, List, TypeVar
from typing_extensions import TypeIs, TypeAlias
from typing_extensions import TypeIs

A = Callable[[object], TypeIs[List[T]]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

T is not defined, why does this test pass?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a general issue with test cases that I've seen in other tests as well. I'm not sure if T is coming from the builtins stubs or whatever else. If you are really interested I could quickly try and search where this has happened.

Obviously still good to point it out and change it here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the root cause of this is that a normal builtins.pyi in typeshed defined _T (which does not get exported) wheres the test fixtures (like dict.pyi) typically use stuff like T (which does get exported).

It would probably be a good idea to change all fixtures, but that might be quite a bit of work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an explicit definition of T in this test. Agree that ideally we should fix this throughout the test suite.

def foo(x: object) -> TypeIs[List[str]]: ...
Expand Down