Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: python/mypy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.10.1
Choose a base ref
...
head repository: python/mypy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.11.0
Choose a head ref

Commits on Apr 15, 2024

  1. Bump version to 1.11.0+dev (#17129)

    The release branch has been cut:
    https://github.com/python/mypy/tree/release-1.10
    Increase the dev version.
    svalentin authored Apr 15, 2024
    Copy the full SHA
    d6d9d8c View commit details

Commits on Apr 16, 2024

  1. fix: incorrect returned type of access descriptors on unions of types (

    …#16604)
    
    Fixes #16603
    
    This change maps over union types when determining the types of access
    descriptors. Previously, the because [this
    conditional](https://github.com/md384/mypy/blob/c2a55afcef32ecb11a4c76c4c79539f6ba36d55c/mypy/checkmember.py#L697-L701)
    would fall through to the `else` case because instance type was not a
    singular `TypeType` (it was a Union), so we'd end up with an instance
    value being passed to `__get__` instead of `None`.
    md384 authored Apr 16, 2024
    Copy the full SHA
    0570f71 View commit details

Commits on Apr 17, 2024

  1. Copy the full SHA
    df35dcf View commit details

Commits on Apr 22, 2024

  1. Fix Literal strings containing pipe characters (#17148)

    Fixes #16367
    
    During semantic analysis, we try to parse all strings as types,
    including those inside Literal[]. Previously, we preserved the original
    string in the `UnboundType.original_str_expr` attribute, but if a type
    is parsed as a Union, we didn't have a place to put the value.
    
    This PR instead always wraps string types in a RawExpressionType node,
    which now optionally includes a `.node` attribute containing the parsed
    type. This way, we don't need to worry about preserving the original
    string as a custom attribute on different kinds of types that can appear
    in this context.
    
    The downside is that more code needs to be aware of RawExpressionType.
    JelleZijlstra authored Apr 22, 2024
    Copy the full SHA
    1072c78 View commit details
  2. Update CONTRIBUTING.md to include commands for Windows (#17142)

    Add command about how to activate virtual environment on Windows.
    GiorgosPapoutsakis authored Apr 22, 2024
    Copy the full SHA
    f7687d3 View commit details
  3. Update CHANGELOG.md with draft for release 1.10 (#17150)

    Initial pass at blog post for Release 1.10.
    
    Still need to add some information about the major changes. Pulled up 3
    commits that seemed like we might want to write something about (under
    TODO), but they can move them to "Other Notable Changes and Fixes" if
    that's not the case.
    svalentin authored Apr 22, 2024
    Copy the full SHA
    810a019 View commit details

Commits on Apr 23, 2024

  1. Copy the full SHA
    c1460f8 View commit details
  2. Update CHANGELOG.md (#17159)

    - add typeshed updates note
    - remove unreleased
    svalentin authored Apr 23, 2024
    Copy the full SHA
    400eece View commit details

Commits on Apr 24, 2024

  1. Copy the full SHA
    43e130b View commit details
  2. docs: remove six from the intersphinx mappings (#17165)

    002f77c removed the last reference to
    six, so there is no need to pull down the six docs inventory
    mr-c authored Apr 24, 2024
    Copy the full SHA
    82ebd86 View commit details

Commits on Apr 26, 2024

  1. docs: Use lower-case generics (#17176)

    Use lower-case `list`, `tuple`, `type` instead of `List`, `Tuple`,
    `Type` in documentation.
    sanxiyn authored Apr 26, 2024
    Copy the full SHA
    6ebce43 View commit details

Commits on Apr 27, 2024

  1. Copy the full SHA
    a1900c2 View commit details
  2. Pin MacOS version in GH actions (#17183)

    Fix failing MacOS tests in CI
    
    Python 3.9 is not available on the latest MacOS images
    actions/setup-python#850
    
    ---------
    
    Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
    hamdanal and cdce8p authored Apr 27, 2024
    Copy the full SHA
    8bc7966 View commit details
  3. Copy the full SHA
    ba6febc View commit details

Commits on May 1, 2024

  1. Copy the full SHA
    cd895ce View commit details
  2. Copy the full SHA
    fb31409 View commit details

Commits on May 10, 2024

  1. Add Error format support, and JSON output option (#11396)

    ### Description
    
    Resolves #10816 
    
    The changes this PR makes are relatively small.
    It currently:
    - Adds an `--output` option to mypy CLI
    - Adds a `ErrorFormatter` abstract base class, which can be subclassed
    to create new output formats
    - Adds a `MypyError` class that represents the external format of a mypy
    error.
    - Adds a check for `--output` being `'json'`, in which case the
    `JSONFormatter` is used to produce the reported output.
    
    #### Demo:
    
    ```console
    $ mypy mytest.py              
    mytest.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int")
    mytest.py:3: error: Name "z" is not defined
    Found 2 errors in 1 file (checked 1 source file)
    
    $ mypy mytest.py --output=json
    {"file": "mytest.py", "line": 2, "column": 4, "severity": "error", "message": "Incompatible types in assignment (expression has type \"str\", variable has type \"int\")", "code": "assignment"}
    {"file": "mytest.py", "line": 3, "column": 4, "severity": "error", "message": "Name \"z\" is not defined", "code": "name-defined"}
    ```
    ---
    A few notes regarding the changes:
    - I chose to re-use the intermediate `ErrorTuple`s created during error
    reporting, instead of using the more general `ErrorInfo` class, because
    a lot of machinery already exists in mypy for sorting and removing
    duplicate error reports, which produces `ErrorTuple`s at the end. The
    error sorting and duplicate removal logic could perhaps be separated out
    from the rest of the code, to be able to use `ErrorInfo` objects more
    freely.
    - `ErrorFormatter` doesn't really need to be an abstract class, but I
    think it would be better this way. If there's a different method that
    would be preferred, I'd be happy to know.
    - The `--output` CLI option is, most probably, not added in the correct
    place. Any help in how to do it properly would be appreciated, the mypy
    option parsing code seems very complex.
    - The ability to add custom output formats can be simply added by
    subclassing the `ErrorFormatter` class inside a mypy plugin, and adding
    a `name` field to the formatters. The mypy runtime can then check
    through the `__subclasses__` of the formatter and determine if such a
    formatter is present.
    The "checking for the `name` field" part of this code might be
    appropriate to add within this PR itself, instead of hard-coding
    `JSONFormatter`. Does that sound like a good idea?
    
    ---------
    
    Co-authored-by: Tushar Sadhwani <86737547+tushar-deepsource@users.noreply.github.com>
    Co-authored-by: Tushar Sadhwani <tushar@deepsource.io>
    3 people authored May 10, 2024
    Copy the full SHA
    35fbd2a View commit details

Commits on May 15, 2024

  1. Sync typeshed (#17246)

    github-actions[bot] authored May 15, 2024
    Copy the full SHA
    b4f9869 View commit details
  2. [dmypy] sort list of files for update by extension (#17245)

    dmypy receives the list of updated files via `--update` flag. If this
    list contains both `foo.py` and `foo.pyi`, the order matters. It seems
    to process the first file in the list first. But if we have a `.pyi`
    file, we want this to be processed first since this one contains the
    typing information.
    Let's reverse sort the list of updated files by the extension. This
    should be a simple enough fix to resolve this.
    
    Though there might be some edge cases where the list of files to update
    contains just pyi files, but we might need to recheck the equivalent py
    files even if not explicitly updated.
    svalentin authored May 15, 2024
    Copy the full SHA
    0a2225b View commit details
  3. Ignore typeshed test files (#17249)

    During the last typehed update, we included the `@tests` folder which is
    unnecessary for mypy.
    Update the `sync-typeshed.py` script to exclude it in the future.
    
    Refs:
    - #17246
    - python/typeshed#11762
    
    ---------
    
    Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
    Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
    3 people authored May 15, 2024
    Copy the full SHA
    cdc956b View commit details

Commits on May 17, 2024

  1. Fix for type narrowing of negative integer literals (#17256)

    Fixes #10514
    Fixes #17118
    
    Negative integer literals were not being correctly handled in the type
    narrowing process, causing mypy errors such as "Statement is
    unreachable" despite the checked code being valid. This fix ensures that
    negative integer literals are properly considered in if-statements.
    gilesgc authored May 17, 2024
    Copy the full SHA
    b74829e View commit details
  2. [PEP 695] Partial support for new type parameter syntax in Python 3.12 (

    #17233)
    
    Add basic support for most features of PEP 695. It's still not generally
    useful, but it should be enough for experimentation and testing. I will 
    continue working on follow-up PRs after this has been merged.
    
    This is currently behind a feature flag:
    `--enable-incomplete-feature=NewGenericSyntax`
    
    These features, among other things, are unimplemented (or at least
    untested):
    * Recursive type aliases
    * Checking for various errors
    * Inference of variance in complex cases
    * Dealing with unknown variance consistently
    * Scoping
    * Mypy daemon
    * Compilation using mypyc
    
    The trickiest remaining thing is probably variance inference in cases
    where some types aren't ready (i.e. not inferred) when we need 
    variance. I have some ideas about how to tackle this, but it might 
    need significant work. Currently the idea is to infer variance
    on demand when we need it, but we may need to defer if variance can't 
    be calculated, for example if a type of an attribute is not yet ready. 
    The current approach is to fall back to covariance in some cases, 
    which is not ideal.
    
    Work on #15238.
    JukkaL authored May 17, 2024
    Copy the full SHA
    5fb8d62 View commit details
  3. [PEP 695] Implement new scoping rules for type parameters (#17258)

    Type parameters get a separate scope with some special features.
    
    Work on #15238.
    JukkaL authored May 17, 2024
    Copy the full SHA
    3b97e6e View commit details

Commits on May 18, 2024

  1. Added [prop-decorator] code for unsupported property decorators (#14461

    …) (#16571)
    
    Using a decorator before a @Property now results in the narrower
    `prop-decorator` code, which is a subcode of `misc` for backward
    compatibility.
    
    I would have preferred to add a more general Unsupported error code and
    have this be a subcode of that, but this has to be a subcode of misc for
    backward compatibility.
    
    Fixes #14461
    analog-cbarber authored May 18, 2024
    Copy the full SHA
    dfab362 View commit details
  2. [mypyc] Show traceback when emitfunc unit test fails (#17262)

    This makes debugging test failures easier.
    JukkaL authored May 18, 2024
    Copy the full SHA
    12837ea View commit details
  3. Copy the full SHA
    828c0be View commit details
  4. stubtest: changes for py313 (#17261)

    Technically it feels like we should be able to put the new dunders on
    `type` or something, but that wasn't enough to make false positives go
    away. But also we might not want to do that because it only applies to
    pure Python types
    hauntsaninja authored May 18, 2024
    Copy the full SHA
    1c83463 View commit details
  5. Copy the full SHA
    c27f4f5 View commit details

Commits on May 19, 2024

  1. [mypyc] Allow specifying primitives as pure (#17263)

    Pure primitives have no side effects, take only immutable arguments,
    and never fail. These properties will enable additional
    optimizations. For example, it doesn't matter in which order
    these primitives are evaluated, and we can perform common
    subexpression elimination on them.
    
    Only mark a few primitives as pure for now, but we can generalize
    this later.
    JukkaL authored May 19, 2024
    Copy the full SHA
    ac8a5a7 View commit details

Commits on May 20, 2024

  1. Stubtest: ignore _ios_support (#17270)

    Trying to import this module on py313 raises RuntimeError on Windows,
    and it doesn't seem important
    AlexWaygood authored May 20, 2024
    Copy the full SHA
    e8a2630 View commit details

Commits on May 21, 2024

  1. Copy the full SHA
    3579c61 View commit details
  2. Add support for __spec__ (#14739)

    Fixes #4145
    
    Co-authored-by: Joongi Kim <me@daybreaker.info>
    hauntsaninja and achimnol authored May 21, 2024
    Copy the full SHA
    f5afdcd View commit details
  3. Fix case involving non-ASCII chars on Windows (#17275)

    Fixes #16669
    
    One can replicate this error in Windows using Python3.8 just by calling
    the mypy/pyinfo.py module using a slightly modified code of the
    `get_search_dirs` function where the python executable doesn't match the
    value of sys.executable. The only modification made to this code from
    `get_search_dirs` is the adding of a non-ascii-path to the env parameter
    alexlshon authored May 21, 2024
    Copy the full SHA
    2892ed4 View commit details
  4. Copy the full SHA
    42157ba View commit details
  5. Automatically set -n=0 when running tests with --update-data (#17204)

    Unless there is a reason to have the error, I think this improves the
    developer experience.
    hamdanal authored May 21, 2024
    Copy the full SHA
    99dd314 View commit details
  6. fix: annotated argument's var node type is explicit, not inferred (#…

    …17217)
    
    Fixes #17216
    
    During conversion from a standard library AST to the mypy AST, `Var`
    nodes were being created inside `Argument` nodes without acknowledging
    the presence of a type annotation, leading to the `Var` node's type as
    being always set as *inferred*:
    
    
    https://github.com/python/mypy/blob/fb31409b392c5533b25173705d62ed385ee39cfb/mypy/nodes.py#L988
    
    This causes an error at
    
    https://github.com/python/mypy/blob/fb31409b392c5533b25173705d62ed385ee39cfb/mypyc/irbuild/expression.py#L161-L164
    
    The fix simply acknowledges any presence of a type annotation, so the
    type of the relevant `Var` node is no longer considered inferred if an
    annotation is present.
    bzoracler authored May 21, 2024
    Copy the full SHA
    ca393dd View commit details

Commits on May 23, 2024

  1. Add support for functools.partial (#16939)

    Fixes #1484
    
    Turns out that this is currently the second most popular mypy issue (and
    first most popular is a type system feature request that would need a
    PEP). I'm sure there's stuff missing, but this should handle most cases.
    hauntsaninja authored May 23, 2024
    4
    Copy the full SHA
    0871c93 View commit details
  2. Validate more about overrides on untyped methods (#17276)

    This commit fixes #9618 by making MyPy always complain if a method
    overrides a base class method marked as `@final`.
    
    In the process, it also adds a few additional validations:
    - Always verify the `@override` decorator, which ought to be pretty
    backward-compatible for most projects assuming that strict override
    checks aren't enabled by default (and it appears to me that
    `--enable-error-code explicit-override` is off by default)
    - Verify that the method signature is compatible (which in practice
    means only arity and argument name checks) *if* the
    `--check-untyped-defs` flag is set; it seems unlikely that a user would
    want mypy to validate the bodies of untyped functions but wouldn't want
    to be alerted about incompatible overrides.
    
    Note: I did also explore enabling the signature compatibility check for
    all code, which in principle makes sense. But the mypy_primer results
    indicated that there would be backward compability issues because too
    many libraries rely on us not validating this:
    #17274
    stroxler authored May 23, 2024
    Copy the full SHA
    25087fd View commit details

Commits on May 24, 2024

  1. Mypybot/sync typeshed (#17280)

    Sync typeshed before 1.11 release.
    
    ---------
    
    Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
    Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
    Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
    4 people authored May 24, 2024
    Copy the full SHA
    43a605f View commit details

Commits on May 25, 2024

  1. Support unions in functools.partial (#17284)

    Co-authored-by: cdce8p
    hauntsaninja authored May 25, 2024
    Copy the full SHA
    3ddc009 View commit details
  2. Fix stubgen for Python 3.13 (#17290)

    __firstlineno__ and __static_attributes__ are new in 3.13.
    __annotate__ will be new in 3.14, so we might as well add it now.
    
    I tried to run the test suite on 3.13. There are a ton of compilation
    failures from mypyc, and a number of stubgen failures that this PR will
    fix.
    JelleZijlstra authored May 25, 2024
    Copy the full SHA
    66b48cb View commit details
  3. Copy the full SHA
    fa2aefc View commit details
  4. Copy the full SHA
    9315d62 View commit details

Commits on May 26, 2024

  1. Don’t leak unreachability from lambda body to surrounding scope (#17287)

    Fixes #17254
    
    Signed-off-by: Anders Kaseorg <andersk@mit.edu>
    andersk authored May 26, 2024
    Copy the full SHA
    5059ffd View commit details

Commits on May 28, 2024

  1. Copy the full SHA
    f60f458 View commit details

Commits on May 30, 2024

  1. [PEP 695] Detect errors related to mixing old and new style features (#…

    …17269)
    
    `Generic[...]` or `Protocol[...]` shouldn't be used with new-style
    syntax.
    
    Generic functions and classes using the new syntax shouldn't mix
    new-style and
    old-style type parameters.
    
    Work on #15238.
    JukkaL authored May 30, 2024
    Copy the full SHA
    7032f8c View commit details
  2. [PEP 695] Support recursive type aliases (#17268)

    The implementation follows the approach used for old-style type aliases.
    
    Work on #15238.
    JukkaL authored May 30, 2024
    Copy the full SHA
    0820e95 View commit details
  3. Add documentation for show-error-code-links (#17144)

    This PR closes issue #16693 and a
    part of issue #17083
    
    Propositional documentation updates for show-error-code-links, which
    update files command_line.rst and config_file.rst.
    
    ---------
    
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    GiorgosPapoutsakis and pre-commit-ci[bot] authored May 30, 2024
    Copy the full SHA
    77cfb98 View commit details

Commits on May 31, 2024

  1. Use Never in more messages, use ambiguous in join (#17304)

    Switches the logic from #16994 to use
    ambiguous (since is_noreturn was only meant for error messages)
    
    See also #15996
    hauntsaninja authored May 31, 2024
    Copy the full SHA
    c3bbd1c View commit details

Commits on Jun 2, 2024

  1. Update 'typing_extensions' to >=4.6.0 to fix python 3.12 error (#17312)

    With earlier versions of typing_extensions, the following traceback is
    seen:
    
    ```
    Traceback (most recent call last):
      File ".../bin/mypy", line 5, in <module>
        from mypy.__main__ import console_entry
      File ".../lib/python3.12/site-packages/mypy/__main__.py", line 9, in <module>
        from mypy.main import main, process_options
      File ".../lib/python3.12/site-packages/mypy/main.py", line 12, in <module>
        from typing_extensions import Final
      File ".../lib/python3.12/site-packages/typing_extensions.py", line 1174, in <module>
        class TypeVar(typing.TypeVar, _DefaultMixin, _root=True):
    TypeError: type 'typing.TypeVar' is not an acceptable base type
    ```
    
    The error is addressed in typing_extensions in
     python/typing_extensions#162, which is included
    in the 4.6.0 release.
    benjamb authored Jun 2, 2024
    Copy the full SHA
    2116386 View commit details
Showing 347 changed files with 13,095 additions and 3,143 deletions.
25 changes: 14 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -36,53 +36,54 @@ jobs:
arch: x64
os: ubuntu-latest
toxenv: py
tox_extra_args: "-n 2"
tox_extra_args: "-n 4"
test_mypyc: true
- name: Test suite with py38-windows-64
python: '3.8'
arch: x64
os: windows-latest
toxenv: py38
tox_extra_args: "-n 2"
tox_extra_args: "-n 4"
- name: Test suite with py39-ubuntu
python: '3.9'
arch: x64
os: ubuntu-latest
toxenv: py
tox_extra_args: "-n 2"
tox_extra_args: "-n 4"
- name: Test suite with py310-ubuntu
python: '3.10'
arch: x64
os: ubuntu-latest
toxenv: py
tox_extra_args: "-n 2"
tox_extra_args: "-n 4"
- name: Test suite with py311-ubuntu, mypyc-compiled
python: '3.11'
arch: x64
os: ubuntu-latest
toxenv: py
tox_extra_args: "-n 2"
tox_extra_args: "-n 4"
test_mypyc: true
- name: Test suite with py312-ubuntu, mypyc-compiled
python: '3.12'
arch: x64
os: ubuntu-latest
toxenv: py
tox_extra_args: "-n 2"
tox_extra_args: "-n 4"
test_mypyc: true

- name: mypyc runtime tests with py39-macos
python: '3.9.18'
arch: x64
os: macos-latest
# TODO: macos-13 is the last one to support Python 3.9, change it to macos-latest when updating the Python version
os: macos-13
toxenv: py
tox_extra_args: "-n 2 mypyc/test/test_run.py mypyc/test/test_external.py"
tox_extra_args: "-n 3 mypyc/test/test_run.py mypyc/test/test_external.py"
- name: mypyc runtime tests with py38-debug-build-ubuntu
python: '3.8.17'
arch: x64
os: ubuntu-latest
toxenv: py
tox_extra_args: "-n 2 mypyc/test/test_run.py mypyc/test/test_external.py"
tox_extra_args: "-n 4 mypyc/test/test_run.py mypyc/test/test_external.py"
debug_build: true

- name: Type check our own code (py38-ubuntu)
@@ -140,7 +141,9 @@ jobs:
pip install -r test-requirements.txt
CC=clang MYPYC_OPT_LEVEL=0 MYPY_USE_MYPYC=1 pip install -e .
- name: Setup tox environment
run: tox run -e ${{ matrix.toxenv }} --notest
run: |
tox run -e ${{ matrix.toxenv }} --notest
python -c 'import os; print("os.cpu_count", os.cpu_count(), "os.sched_getaffinity", len(getattr(os, "sched_getaffinity", lambda *args: [])(0)))'
- name: Test
run: tox run -e ${{ matrix.toxenv }} --skip-pkg-install -- ${{ matrix.tox_extra_args }}

@@ -189,4 +192,4 @@ jobs:
- name: Setup tox environment
run: tox run -e py --notest
- name: Test
run: tox run -e py --skip-pkg-install -- -n 2 mypyc/test/
run: tox run -e py --skip-pkg-install -- -n 4 mypyc/test/
Loading