Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit resolves a subtle interaction between PEP 563 (i.e., `from __future__ import annotations`), PEP 673 (i.e., `typing{_extension}.Self`), and standard dunder methods (e.g., `__add__()`), partially resolving issue #367 kindly submitted by Dark Typing Priestess of Darkness @iamrecursion (Ara Adkins). Specifically, this commit ensures that the type stack encapsulating the current `@beartype`-decorated class is now preserved throughout the type-checking process for standard dunder methods annotated by one or more PEP 673-compliant `typing{_extension}.Self` type hints that are stringified under PEP 563. For example, @beartype now transparently supports pernicious edge cases resembling: ```python from beartype import beartype from typing_extensions import Self @beartype class MyClass: attribute: int def __init__(self, attr: int) -> None: self.attribute = attr def __add__(self, other: int) -> Self: self.__class__(self.attribute + other) ``` (*Rubicons of iconic rubes!*)
- Loading branch information
Showing
8 changed files
with
68 additions
and
16 deletions.
There are no files selected for viewing
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
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
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