- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 29
Add Mypy configuration through root "pyproject.toml" file #135
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
          
     Open
      
      
            Delgan
  wants to merge
  1
  commit into
  typeddjango:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
Delgan:GH-133-add-plugin-config
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
  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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -195,6 +195,22 @@ mypy-tests: | |
|  | ||
| ``` | ||
|  | ||
| ## Configuration | ||
|  | ||
| For convenience, it is also possible to define a default `mypy` configuration in the root `pyproject.toml` file of your project: | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, also describe what priority this setting has over CLI flags / etc. | ||
|  | ||
| ```toml | ||
| [tool.pytest-mypy-plugins.mypy-config] | ||
| force_uppercase_builtins = true | ||
| force_union_syntax = true | ||
| ``` | ||
|  | ||
| The ultimate `mypy` configuration applied during a test is derived by merging the following sources (if they exist), in order: | ||
|  | ||
| 1. The `mypy-config` table in the root `pyproject.toml` of the project. | ||
| 2. The configuration file provided via `--mypy-pyproject-toml-file` or `--mypy-ini-file`. | ||
| 3. The `config_mypy` field of the test case. | ||
|  | ||
| ## Further reading | ||
|  | ||
| - [Testing mypy stubs, plugins, and types](https://sobolevn.me/2019/08/testing-mypy-types) | ||
|  | ||
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1 +1 @@ | ||
| # This file has no `[tool.mypy]` existing config | ||
| # This file has no `[tool.mypy]` nor `[tool.pytest-mypy-plugins.mypy-config]` existing config | 
  
    
      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,10 @@ | ||
| # This file has `[tool.pytest-mypy-plugins.mypy-config]` existing config | ||
|  | ||
| [tool.pytest-mypy-plugins.mypy-config] | ||
| pretty = false | ||
| show_column_numbers = true | ||
| warn_unused_ignores = false | ||
|  | ||
| [tool.other] | ||
| # This section should not be copied: | ||
| key = 'value' | 
  
    
      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
    
  
  
    
              
        
          
          
            20 changes: 20 additions & 0 deletions
          
          20 
        
  pytest_mypy_plugins/tests/test_configs/test_load_mypy_plugins_config.py
  
  
      
      
   
        
      
      
    
  
    
      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,20 @@ | ||
| from pathlib import Path | ||
| from typing import Final | ||
|  | ||
| from pytest_mypy_plugins.configs import load_mypy_plugins_config | ||
|  | ||
|  | ||
| def test_load_existing_config() -> None: | ||
| root_pyproject1: Final = str(Path(__file__).parent / "pyproject3.toml") | ||
| result = load_mypy_plugins_config(root_pyproject1) | ||
| assert result == { | ||
| "pretty": False, | ||
| "show_column_numbers": True, | ||
| "warn_unused_ignores": False, | ||
| } | ||
|  | ||
|  | ||
| def test_load_missing_config() -> None: | ||
| root_pyproject2: Final = str(Path(__file__).parent / "pyproject2.toml") | ||
| result = load_mypy_plugins_config(root_pyproject2) | ||
| assert result is 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.
This is unrelated to the other changes I made.
Current
masterbranch is failing with latest version of Mypy for a reason I'm not sure to understand.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.
Can you please provide a traceback?
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.
@sobolevn Sure:
This can be reproduced by executing
mypy --no-silence-site-packages --no-strict-optionalon the following file:Mypy v1.6.0+ flags this snippet as invalid and exits with non-zero:
This doesn't happen when
--no-silence-site-packagesis omitted.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.
--no-strict-optionalis not tested much in mypy (and for a good reason - it should not be used).How does it affect us here?
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.
It is used to verify that inline
mypy_configworks as expected: https://github.com/typeddjango/pytest-mypy-plugins/blob/master/pytest_mypy_plugins/tests/test-mypy-config.ymlWe can probably test it with another option, though.
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.
I stumbled upon this pr because tests failed with mypy-1.8.0 (https://bugs.gentoo.org/921901). (Where) has the regression been reported upstream?