Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Optional[ClassType]" = None was rewrite to Optional["Optional[ClassType]"] = None #19

Open
xiaoyanli-lyft opened this issue Dec 7, 2023 · 1 comment

Comments

@xiaoyanli-lyft
Copy link

xiaoyanli-lyft commented Dec 7, 2023

Mypy does not care about double quotes, and treat them same. However, no_implicit_optional still add additional Optional, like below will be transform to

def example_function_double_quote(x: Optional["Optional[DummyClass]"]=None) -> None:

Can we fix this edge case?

from typing import Optional


class DummyClass:
    """A dummy class for illustration purposes."""

    def __init__(self, name: str):
        self.name = name

    def greet(self) -> str:
        """A dummy method that returns a greeting."""
        return f"Hello, {self.name}!"

def example_function_double_quote(x: "Optional[DummyClass]"=None) -> None:
    reveal_type(x)  

def example_function(x: Optional[DummyClass]=None) -> None:
    reveal_type(x)  
    
example_function(DummyClass("hello"))
example_function_double_quote(DummyClass("hello"))

and when run about code:

test.py:15: note: Revealed type is "Union[test.DummyClass, None]"
test.py:18: note: Revealed type is "Union[test.DummyClass, None]"
Success: no issues found in 1 source file
@hauntsaninja
Copy link
Owner

Thanks for the issue! Agree this is undesirable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants