Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

documentation for TypeIs#17821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JukkaL merged 9 commits intopython:masterfromchelseadz:documentTypeIs
Oct 9, 2024
Merged
Changes from1 commit
Commits
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
PrevPrevious commit
fix PEP number, duplicate paragraph and revealed type for int
  • Loading branch information
chelseadz committedOct 8, 2024
commitc3c9fa981e110890d5741a9217f3ca5849e3ad0a
8 changes: 2 additions & 6 deletionsdocs/source/type_narrowing.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -396,7 +396,7 @@ or rewrite the function to be slightly more verbose:
TypeIs
------

Mypy supports TypeIs (:pep:`754`).
Mypy supports TypeIs (:pep:`742`).

A `TypeIs narrowing function <https://typing.readthedocs.io/en/latest/spec/narrowing.html#typeis>`_
allows you to define custom type checks that can narrow the type of a variable
Expand DownExpand Up@@ -448,10 +448,6 @@ Key points:
TypeIs vs TypeGuard
~~~~~~~~~~~~~~~~~~~

While both TypeIs and TypeGuard allow you to define custom type narrowing
functions, they differ in important ways:


While both TypeIs and TypeGuard allow you to define custom type narrowing
functions, they differ in important ways:

Expand DownExpand Up@@ -518,7 +514,7 @@ The type narrowing applies only to the first argument.

def process(x: Any) -> None:
if is_instance_of(x, int):
reveal_type(x) # Revealed type is 'int' or any int subclass
reveal_type(x) # Revealed type is 'int'
print(x + 1) # ok
else:
reveal_type(x) # Revealed type is 'Any'
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp