- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33.3k
          bpo-46333: Honor module parameter in ForwardRef
          #30536
        
          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
      
      
            JelleZijlstra
  merged 13 commits into
  python:main
from
aha79:bpo_46333_eq_and_repr_for_forwardref
  
      
      
   
  Feb 17, 2022 
      
    
  
     Merged
                    Changes from 1 commit
      Commits
    
    
            Show all changes
          
          
            13 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      980ea28
              
                bpo-46333: Honor `module` parameter in ForwardRef
              
              
                andreas-h-sie 82fa061
              
                📜🤖 Added by blurb_it.
              
              
                blurb-it[bot] ac51d98
              
                Update Lib/test/test_typing.py
              
              
                aha79 d643861
              
                Update Lib/typing.py
              
              
                aha79 ac16c5c
              
                Update Misc/NEWS.d/next/Library/2022-01-11-15-54-15.bpo-46333.B1faiF.rst
              
              
                aha79 a2e1377
              
                Update ACKS
              
              
                andreas-h-sie c084fdb
              
                Update Misc/NEWS.d/next/Library/2022-01-11-15-54-15.bpo-46333.B1faiF.rst
              
              
                aha79 7577633
              
                Remove module output from __repr__
              
              
                andreas-h-sie d608058
              
                Merge branch 'bpo_46333_eq_and_repr_for_forwardref' of github.com:aha…
              
              
                andreas-h-sie 3df5009
              
                take out repr change
              
              
                andreas-h-sie 42fc26b
              
                Update Misc/NEWS.d/next/Library/2022-01-11-15-54-15.bpo-46333.B1faiF.rst
              
              
                aha79 9dd2f8f
              
                add tests for ForwardRef.hash
              
              
                andreas-h-sie 94c9a69
              
                move ForwardRef.__hash__ test to correct function
              
              
                andreas-h-sie 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
    
  
  
    
              
  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.
Hmm, I wonder if this test is run directly, will
__name__be `main``? Wouldn't that make the test pass incorrectly? (Throwing this question out there because I'm not too sure myself). Maybe we should be safe and give it a distinct name?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.
The test is to ensure that
ForwardRefwithmoduleset is different fromForwardRefwithmodulenot set (That was previsously not the case). The actual value ofmodule(or__name__) is not relevant. Under the hood the comparison isNonevsstrUh oh!
There was an error while loading. Please reload this page.
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.
My bad, thanks for pointing that out. I mistakenly assumed it would grab a default value from the current scope to populate
modulein things likeClassVar['int']due to the_type_check/_type_convertfunction (I'm now shocked that it doesn't and only does that forTypedDict).Uh oh!
There was an error while loading. Please reload this page.
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, unfortunately the current module is not captured automatically.
The current scope/module is typicallly obtained by
get_type_hintsbecause a class knows its module (and so all ForwardRefs in member annotations can be correctly resolved. But each forward Ref does originally not know its module).However for type aliases this does not work, and there one needs the explicit module.
For example
Json = Union[ List['Json'], Dict[str,'Json'], int, float, bool, None ]
cannot be exported (and expect to work) unless one sets the
modulefor each forward ref.