-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation for exec_type_checking
- Loading branch information
Showing
8 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
13 changes: 13 additions & 0 deletions
13
docs/examples/loading-and-dumping/extended_usage/dealing_with_type_checking/chat.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# ruff: noqa: UP035, UP006 | ||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING, List | ||
|
||
if TYPE_CHECKING: | ||
from .message import Message | ||
|
||
|
||
@dataclass | ||
class Chat: | ||
id: int | ||
name: str | ||
messages: List["Message"] |
15 changes: 15 additions & 0 deletions
15
...amples/loading-and-dumping/extended_usage/dealing_with_type_checking/error_on_analysis.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from typing import get_type_hints | ||
|
||
from .chat import Chat | ||
from .message import Message | ||
|
||
try: | ||
get_type_hints(Chat) | ||
except NameError as e: | ||
assert str(e) == "name 'Message' is not defined" | ||
|
||
|
||
try: | ||
get_type_hints(Message) | ||
except NameError as e: | ||
assert str(e) == "name 'Chat' is not defined" |
22 changes: 22 additions & 0 deletions
22
docs/examples/loading-and-dumping/extended_usage/dealing_with_type_checking/main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# ruff: noqa: UP035, UP006 | ||
from typing import List, get_type_hints | ||
|
||
from adaptix.type_tools import exec_type_checking | ||
|
||
from . import chat, message | ||
|
||
# You pass the module object | ||
exec_type_checking(chat) | ||
exec_type_checking(message) | ||
|
||
# After these types can be extracted | ||
assert get_type_hints(chat.Chat) == { | ||
"id": int, | ||
"name": str, | ||
"messages": List[message.Message], | ||
} | ||
assert get_type_hints(chat.Message) == { | ||
"id": int, | ||
"text": str, | ||
"chat": chat.Chat, | ||
} |
12 changes: 12 additions & 0 deletions
12
docs/examples/loading-and-dumping/extended_usage/dealing_with_type_checking/message.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from dataclasses import dataclass | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from .chat import Chat | ||
|
||
|
||
@dataclass | ||
class Message: | ||
id: int | ||
text: str | ||
chat: "Chat" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters