- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33.2k
gh-118660: Add second type parameter to (Async)ContextManager #118681
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
          
     Merged
      
        
      
    
  
     Merged
                    Changes from 7 commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      1013ef3
              
                gh-118660: Add second type parameter to (Async)ContextManager
              
              
                JelleZijlstra 2d9458e
              
                Add code
              
              
                JelleZijlstra 5dd6535
              
                Fix docs warnings
              
              
                JelleZijlstra 7d79f10
              
                Merge branch 'main' into cmgen
              
              
                JelleZijlstra 059432a
              
                Update typing.rst
              
              
                JelleZijlstra 8592fa2
              
                Apply suggestions from code review
              
              
                JelleZijlstra b3f2484
              
                Apply suggestions from code review
              
              
                JelleZijlstra 865fffc
              
                Apply suggestions from code review
              
              
                JelleZijlstra File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
        
          
          
            4 changes: 4 additions & 0 deletions
          
          4 
        
  Misc/NEWS.d/next/Library/2024-05-06-18-13-02.gh-issue-118660.n01Vb7.rst
  
  
      
      
   
        
      
      
    
  
    
      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
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Add a second type parameter to :class:`typing.ContextManager` and | ||
|         
                  JelleZijlstra marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| :class:`typing.AsyncContextManager`, representing the return types of | ||
| :meth:`~object.__exit__` and :meth:`~object.__aexit__` respectively. | ||
| This parameter defaults to ``bool | None``. | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would maybe put a little bit more emphasis on the new type parameter being optional. While it defaulting to
bool | Noneimplies that, it's maybe a little bit too subtle for user-facing documentation, especially for a new feature in 3.13.We could also consider changing the notation from
Generic[T_co, ExitT_co]toGeneric[T_co, ExitT_co = bool | None], so its behavior can be inferred just from this header, similar to function signatures, even if that is not valid syntax, it's similar to PEP-695 notation, while retaining the implicit reference toGenericwithin the typing module.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered that syntax with Generic but didn't use it here because it's a SyntaxError. Switching to PEP 695 syntax might be nice but I think it causes problems with Sphinx. In any case, this is something we can adjust after the beta.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we have to use an old version of Sphinx to keep Linux redistributors happy, and old versions of Sphinx don't know about PEP-695 syntax so they do weird things with the syntax highlighting