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

F821 and F722 errors when importing from typing_extensions in version 0.0.94 #548

Closed
StefanBRas opened this issue Nov 2, 2022 · 3 comments · Fixed by #550
Closed

F821 and F722 errors when importing from typing_extensions in version 0.0.94 #548

StefanBRas opened this issue Nov 2, 2022 · 3 comments · Fixed by #550

Comments

@StefanBRas
Copy link
Contributor

Importing from typing_extensions instead of typing gives some errors with ruff version 0.0.94

from typing_extensions import Literal, List
from pydantic import BaseModel
from dataclasses import dataclass 

f821_outer = Literal['x']              # No errors
f722_outer = Literal['+', "-"]         # No errors        
f821_List = List[Literal['x']]         # No errors             
f722_List = List[Literal['+','-']]     # No errors             

class Tmp(BaseModel):
    a: Literal['x']                    # F821 Undefined name `x`                   
    b: Literal['+', "-"]               # F722 Syntax error in forward annotation: `+`, # F722 Syntax error in forward annotation: `-`              
    c: List[Literal['x']]              # F821 Undefined name `x`                                
    d: List[Literal['+','-']]          # F722 Syntax error in forward annotation: `+`, # F722 Syntax error in forward annotation: `-`             
    e: f821_outer                      # No errors                     
    f: f722_outer                      # No errors                        

@dataclass
class Tmp1:
    a: Literal['x']                    # F821 Undefined name `x`                                      
    b: Literal['+', "-"]               # F722 Syntax error in forward annotation: `+`, # F722 Syntax error in forward annotation: `-`                    
    c: List[Literal['x']]              # F821 Undefined name `x`                                
    d: List[Literal['+','-']]          # F722 Syntax error in forward annotation: `+`, # F722 Syntax error in forward annotation: `-`             
    e: f821_outer                      # No errors                        
    f: f722_outer                      # No errors                        

def tmp(
    a: Literal['x'],                   # F821 Undefined name `x`                   
    b: Literal['+', "-"],              # F722 Syntax error in forward annotation: `+`, # F722 Syntax error in forward annotation: `-`      
    c: List[Literal['x']],             # F821 Undefined name `x`                                
    d: List[Literal['+','-']],         # F722 Syntax error in forward annotation: `+`, # F722 Syntax error in forward annotation: `-`
    e: f821_outer,                     # No errors                        
    f: f722_outer,                     # No errors                        
    ):
    pass

yields

Found 18 error(s).
f821.py:11:15: F821 Undefined name `x`
f821.py:12:15: F722 Syntax error in forward annotation: `+`
f821.py:12:20: F722 Syntax error in forward annotation: `-`
f821.py:13:20: F821 Undefined name `x`
f821.py:14:20: F722 Syntax error in forward annotation: `+`
f821.py:14:24: F722 Syntax error in forward annotation: `-`
f821.py:20:15: F821 Undefined name `x`
f821.py:21:15: F722 Syntax error in forward annotation: `+`
f821.py:21:20: F722 Syntax error in forward annotation: `-`
f821.py:22:20: F821 Undefined name `x`
f821.py:23:20: F722 Syntax error in forward annotation: `+`
f821.py:23:24: F722 Syntax error in forward annotation: `-`
f821.py:28:15: F821 Undefined name `x`
f821.py:29:15: F722 Syntax error in forward annotation: `+`
f821.py:29:20: F722 Syntax error in forward annotation: `-`
f821.py:30:20: F821 Undefined name `x`
f821.py:31:20: F722 Syntax error in forward annotation: `+`
f821.py:31:24: F722 Syntax error in forward annotation: `-`

When changing the import from typing_extensions to typing I get 0 errors.
When using ruff version 0.0.93 I get 0 errors (using either import)

@charliermarsh
Copy link
Member

Thank you! Will fix this today.

@charliermarsh
Copy link
Member

Thanks for this and apologies for the oversight. This is going out in v0.0.95 (building now).

@StefanBRas
Copy link
Contributor Author

No worries, I can hardly complain when there's a fix two hours after reporting.

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

Successfully merging a pull request may close this issue.

2 participants