Created
December 27, 2025 18:53
-
-
Save mypy-play/8fbe0316234691cdc2f8e85e324d56e9 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
This file contains hidden or 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
| from pathlib import Path | |
| class MyClass: | |
| def __init__(self, path: Path | None) -> None: | |
| self.path = path | |
| def test(a: MyClass, b: MyClass): | |
| if a.path is None: | |
| raise ValueError(f"a.path cannot be None") | |
| if b.path is None: | |
| raise ValueError(f"b.path cannot be None") | |
| # This line will cause an error for the line "b.path.exists()": error: Item "None" of "Path | None" has no attribute "exists" [union-attr] | |
| b = a | |
| if a.path.exists(): | |
| print("a path exist") | |
| if b.path.exists(): | |
| print("b path exist") | |
| def main(): | |
| a = MyClass(Path(".")) | |
| b = MyClass(Path(".")) | |
| test(a, b) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment