Skip to content
Permalink
Branch: release-0.720
Commits on Jul 12, 2019
  1. Bump version to 0.720

    Ivan Levkivskyi
    Ivan Levkivskyi committed Jul 12, 2019
Commits on Jul 9, 2019
  1. Support selecting TypedDicts from unions (#7184)

    ilevkivskyi committed Jul 9, 2019
    It is a relatively common pattern to narrow down typed dicts from unions with non-dict types using `isinstance(x, dict)`. Currently mypy infers `Dict[Any, Any]` after such checks which is suboptimal.
    
    I propose to special-case this in `narrow_declared_type()` and `restrict_subtype_away()`. Using this opportunity I factored out special cases from the latter in a separate helper function.
    
    Using this opportunity I also fix an old type erasure bug in `isinstance()` checks (type should be erased after mapping to supertype, not before).
  2. Fix mismatched reference to ``dotted_module_name`` (#7179)

    deepyaman authored and JelleZijlstra committed Jul 9, 2019
  3. New semantic analyzer: fix crash on broken overload at class scope (#…

    ilevkivskyi committed Jul 9, 2019
    …7181)
    
    Fixes #7044
    
    The crash is caused by the fact that `.type` for broken overloads can be `None`. There is another example where we deal with this in `analyze_ref_expr()`. The crash doesn't happen on the old analyzer because it doesn't add the broken overload to the symbol table.
    
    I solve the crash by generating a dummy `Overloaded()` type in this case. An alternative solution would be to re-analyze a broken overload as independent (re-)definitions, but I think this is more error-prone to keep an overload in AST, but a bunch of functions in symbol table.
    
    Using this opportunity I also remove a redundant `add_symbol()` call (we always add the overload before even processing it).
    
    Note that the behavior of the new analyzer is still different from the old one, but IMO it is more consistent in some sense.
  4. Enable new semantic analyzer by default (#7174)

    ilevkivskyi committed Jul 9, 2019
    The old semantic analyzer is still there and can be used with `--no-new-semantic-analyzer`. For running tests one can use `NEWSEMANAL=0`.
  5. Add union math for intelligent indexing (#6558)

    Michael0x2a committed Jul 9, 2019
    This pull request hacks on supports for union math when using Unions of
    Literals to index into tuples, NamedTuples, and TypedDicts.
    
    It also fixes a bug I apparently introduced. Currently, mypy correctly
    reports an error with this code:
    
        class Test(TypedDict):
            foo: int
    
        t: Test
    
        # Error: int can't be assigned a str value
        t.setdefault("foo", "unrelated value")
    
    ...but does not report an error with:
    
        key: Literal["foo"]
        t.setdefault(key, "unrelated value")
    
    This diff should make mypy report an error in both cases.
    
    Resolves #6262.
Commits on Jul 8, 2019
  1. Don't define a duplicate __init__ for dataclasses (#7168)

    refi64 authored and ilevkivskyi committed Jul 8, 2019
    Closes #6399.
  2. Fix self-check (and therefore mypyc) on older Python versions (#7176)

    ilevkivskyi committed Jul 8, 2019
    This also implements one of my old wishes: `UnionType.make_simplified_union()` should not mutate its argument.
  3. Sync typeshed (#7175)

    ilevkivskyi committed Jul 8, 2019
  4. New analyzer: add more tests for order of processing (#7173)

    JukkaL committed Jul 8, 2019
    Closes #6341.
  5. Add more details for "Invalid type" errors (#7166)

    ilevkivskyi committed Jul 8, 2019
    Fixes #4030
    
    This adds some more details to various `Invalid type` errors, and similar such as `Invalid type alias`, and `Invalid base class`. Unfortunately, `MessageBuilder` is not available in `typeanal.py`, so I put some error message formatting logic there.
  6. Fix overlap between TypedDict and Mapping (#7164)

    ilevkivskyi committed Jul 8, 2019
    Fixes #7036
    
    This adds more "fine grained" logic for overlap between `TypedDict` and `Mapping` used by overload checks and `--strict-equality`. Basically the rules are:
    * A `TypedDict` with some required keys is overlapping with `Mapping[str, <some type>]` if and only if every key type is overlapping with `<some type>`.
    * A `TypedDict` with no required keys overlaps with `Mapping[str, <some type>]` if and only if at least one of key types overlaps with `<some type>`.
    * Empty dictionaries are as usual in gray area, so we follow the same logic as in other places: an empty dictionary can't cause an overlap (i.e. `TypedDict` with no required keys doesn't overlap with `Mapping[str, <some type>]`), but is itself (i.e. `Mapping[<nothing>, <nothing>]`) overlapping with a `TypedDict` with no required keys.
  7. Generalize reachability checks to support enums (#7000)

    Michael0x2a authored and ilevkivskyi committed Jul 8, 2019
    Fixes #1803
    
    This diff adds support for performing reachability and narrowing analysis when doing certain enum checks.
    
    For example, given the following enum:
    
        class Foo(Enum):
            A = 1
            B = 2
    
    ...this pull request will make mypy do the following:
    
        x: Foo
        if x is Foo.A:
            reveal_type(x)  # type: Literal[Foo.A]
        elif x is Foo.B:
            reveal_type(x)  # type: Literal[Foo.B]
        else:
            reveal_type(x)  # No output: branch inferred as unreachable
    
    This diff does not attempt to perform this same sort of narrowing for equality checks: I suspect implementing those will be harder due to their overridable nature. (E.g. you can define custom `__eq__` methods within Enum subclasses).
    
    This pull request also finally adds support for the enum behavior [described in PEP 484][0] and also sort of partially addresses #6366
    
      [0]: https://www.python.org/dev/peps/pep-0484/#support-for-singleton-types-in-unions
  8. New analyzer: reverse order of modules within SCC (#7163)

    JukkaL committed Jul 8, 2019
    This brings the new semantic analyzer closer to the old one and 
    slightly helps performance.
  9. Add docs for the '--warn-unreachable' flag (#7170)

    Michael0x2a authored and ilevkivskyi committed Jul 8, 2019
    This pull request adds a segment about the '--warn-unreachable' flag
    to the command line docs page and a shorter blurb to the config files
    page.
  10. Avoid telling the user to use type annotations on pre-3.5 (#7167)

    refi64 authored and ilevkivskyi committed Jul 8, 2019
    Closes #6673
Commits on Jul 5, 2019
  1. Add infrastructure for testing order of processing nodes in new analy…

    ilevkivskyi committed Jul 5, 2019
    …ser (#7160)
    
    See #6341
    
    This PR doesn't add actual tests, just the infra. I simply expose the existing machinery we use in the fine grained mode also to the normal tests.
    
    Using this opportunity I also refactor `assert_module_equivalence()` and `assert_target_equivalence()` by moving `is None` checks to callers.
  2. New analyzer: update documentation of becomes_typeinfo (#7161)

    JukkaL committed Jul 5, 2019
    In some cases we don't know whether something could become a TypeInfo,
    but it might. Not sure if this is the best way to do this, but this
    helps in some scenarios (but could cause problems in others, perhaps).
    
    Follow-up to #7158.
  3. New analyzer: fix issues with order-dependent results (#7158)

    JukkaL committed Jul 5, 2019
    When we add a placeholder, we should do it through `mark_incomplete`,
    since the name needs to added to the set of missing names. Otherwise
    a later definition can take precedence over an earlier definition,
    if the first definition initially creates a placeholder.
    
    Fixes #7157 and probably another issue related to type aliases, which
    was exposed by the fix.
  4. New analyzer: improve documentation of defer() (#7159)

    JukkaL committed Jul 5, 2019
    This concludes documentation that started in #7130 and #7135.
    
    Closes #7071.
  5. Fix binding of self-types on unions (#7152)

    ilevkivskyi committed Jul 5, 2019
    Fixes #7149
    
    The fix is quite straightforward, self-types should be bound to each individual component, so I just added only basic tests. Please let me know if you want better test coverage (properties, class-methods) etc.
  6. Fix --strict-equality for decorated and aliased __eq__ methods (#7156)

    ilevkivskyi committed Jul 5, 2019
    Fixes #7035
    
    The fix is straightforward: we use `get()` instead of `get_method()` and check for more symbol kinds.
Commits on Jul 4, 2019
  1. New analyzer: Fix Any kinds for special forms (#7148)

    ilevkivskyi committed Jul 4, 2019
    Fixes #7118
    
    Previously left hand sides of special forms were inferred as `TypeOfAny.from_error`. Note that _total_ number of expressions in one of the tests is now smaller because of the subtle logic in visiting definitions of special forms, but I don't think it is import to keep it one-to-one with old analyser.
  2. New analyzer: test that class properties are calculated for classes i…

    ilevkivskyi committed Jul 4, 2019
    …n functions (#7147)
    
    Fixes #6494
    
    The issue seems to be already fixed because of how `local_definitions()` works, I just add a test case to avoid regressions.
  3. Make sure that SymbolTableNode.node is not unexpectedly None (#7146)

    JukkaL committed Jul 4, 2019
    These might help diagnose some crashes we've seen.
  4. Print simple deferral debug trace in case of a hang (#6942)

    ilevkivskyi committed Jul 4, 2019
  5. New semantic analyzer: fix issues with 'X = X' assignments (#7144)

    JukkaL committed Jul 4, 2019
    We special case these since a more general fix, such as looking
    at line numbers of definitions, would break a ton of test cases.
    
    Fixes #6404.
  6. Support method plugin hooks on unions (#6560)

    ilevkivskyi committed Jul 4, 2019
    Fixes #6117
    Fixes #5930
    
    Currently both our plugin method hooks don't work with unions. This PR fixes this with three things:
    * Moves a bit of logic from `visit_call_expr_inner()` (which is a long method already) to `check_call_expr_with_callee_type()` (which is a short method).
    * Special-cases unions in `check_call_expr_with_callee_type()` (normal method calls) and `check_method_call_by_name()` (dunder/operator method calls).
    * Adds some clarifying comments and a docstring.
    
    The week point is interaction with binder, but IMO this is the best we can have for now. I left a comment mentioning that check for overlap should be consistent in two functions.
    
    In general, I don't like special-casing, but I spent several days thinking of other solutions, and it looks like special-casing unions in couple more places is the only reasonable way to fix unions-vs-plugins interactions.
    
    This PR may interfere with #6558 that fixes an "opposite" problem, hopefully they will work together unmodified, so that accessing union of literals on union of typed dicts works. Whatever PR lands second, should add a test for this.
Commits on Jul 3, 2019
  1. modulefinder: use only dirs containing no __init__.py as namespace p…

    awelzel authored and gvanrossum committed Jul 3, 2019
    …ackage (#7108)
    
    When used with --namespace-packages, a directory containing no __init__.pyi
    was previously added as a candidate to near_misses even if it contained
    a __init__.py. This logic doesn't seem sensible, particularly as this
    directory was then chosen as the result of find_module() instead of
    the __init__.py inside the directory.
    
    Closes #5854.
  2. New analyser: Fix crash in plugins when star import blocks adding a s…

    ilevkivskyi committed Jul 3, 2019
    …ymbol (#7136)
    
    Fixes #7076
    
    The fix is pretty straightforward. I also add a comment about `missing_names` being per-module, not per namespace.
  3. Add some more telemetry to graph loading (#7139)

    msullivan authored and ilevkivskyi committed Jul 3, 2019
    Internal telemetry shows it to be a hot spot in practice and I want to
    dig a little deeper.
    
    Gate some potentially expensive logging code on this path, while I'm
    at it.
  4. Document how plugins can support the new semantic analyzer (#7135)

    JukkaL committed Jul 3, 2019
    Work towards #7071 (and more).
  5. Fix error reporting context for missing generic type arguments (#7100)

    ilevkivskyi committed Jul 3, 2019
    Fixes #7077
    
    The logic of the fix is quite straightforward: emit the error immediately when we fix an instance type, and not in a traversal after the main pass. Note that I fix this only for the new analyser, because the old one will be anyway deprecated soon.
    
    This causes a bit of code churn because we need to pass the flags to several functions, but the logic should not change much. I didn't add many new tests, since we have a bunch of existing tests. It would probably make sense to play with this, suggestions for more tests are very welcome.
Commits on Jul 2, 2019
  1. Don't do any tricky inference in deferred nodes (#7134)

    ilevkivskyi committed Jul 2, 2019
    Fixes #7126
Older
You can’t perform that action at this time.