master
Commits on Apr 21, 2021
-
TypedDict incompatible type message more understandable (#10326)
Added a section to the incompatible_argument function in mypy.messages that is executed when trying to add an incompatible type to a TypedDict. Required adding some imports from mypy.nodes to allow for the isinstance to work. Fixes #10253
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Fix type annotations in an example (#10351)
Changed the return type annotation for `__init__` from `int` to `None`
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Remove types-typing-extensions dependency (#10347)
This is due to python/typeshed#5233 Co-authored-by: hauntsaninja <>
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
* Sync typeshed Source commit: python/typeshed@fc660d6 * fix test Co-authored-by: hauntsaninja <>
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Stop running Python 3.5 in CI, run Python 3.9 with mypyc (#10345)
* Stop running Python 3.5 in CI Python 3.5 always fails in CI these days Linking #9950 * Run 3.9 tests with mypyc Co-authored-by: hauntsaninja <>
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Use double quotes in errors `Duplicate argument` and `Cannot assign m…
…ultiple modules` (#10344)
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits
Commits on Apr 20, 2021
-
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits
Commits on Apr 19, 2021
-
Use double quotes in "already defined" errors and others (#10335)
Also covers `is nonlocal and global`, `No binding for nonlocal` and `is already defined in local`.
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits
Commits on Apr 13, 2021
-
Make --explicit-package-bases invertible (#9969)
Closes #9968 This PR adds the inverse of --explicit-package-bases: --no-explicit-package-bases. The flag can be used if you want to override explicit_package_bases = True which was set in a configuration file.
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Fix crash for protocol classes, Hashable false negative (#10308)
Fix function `is_protocol_implementation` for quite similar protocol classes. Fixes #9771 ``` from typing import Protocol, TypeVar, Union T1 = TypeVar("T1", covariant=True) T2 = TypeVar("T2") class P1(Protocol[T1]): def b(self) -> int: ... def a(self, other: "P1[T2]") -> T1: ... class P2(Protocol[T1]): def a(self, other: Union[P1[T2], "P2[T2]"]) -> T1: ... ``` Method `infer_constraints_from_protocol_members` of class `ConstraintBuilderVisitor` raises an assertion for the above code when we pass `P2` as `instance` and `P1` as `template` to it (inline comment: _The above is safe since at this point we know that 'instance' is a subtype of (erased) 'template', therefore it defines all protocol members_). So, the actual error happens before. Method `visit_instance` of class `ConstraintBuilderVisitor` should never apply the method `infer_constraints_from_protocol_members` on `P1` and `P2`. It nevertheless does so due to function `is_protocol_implementation` indicating `P2` actually implements `P1`. In my naive understanding, the problem seems to lie in the recursive approach underlying function `is_protocol_implementation`. This function first analyses method `a` to check if `P2` is a subclass of `P1`. Therefore, it needs to check if `P1` is a subclass of `P2`. This can result in a situation where the "'assuming' structural subtype matrix" is already filled with `P1` and `P2`. `is_protocol_implementation` then returns `True` (for avoiding infinite recursion in other cases) without checking any other members, which is incorrect for the given case. The simple check only relies on the subset relationship of the member names. Eventually, it avoids the more complicated recursive search for potential discrepancies. I do not know if it positively affects performance, but it fixes #9771.
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits
Commits on Apr 12, 2021
-
There were several things to improve in Final docs: 1. For some reason it was `ID: Final[float] = 1`, while 1 is clearly int 2. There was also a quite misleading phrase about `ID: Final = 1` being int and not Literal[1]
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Check for AnyType after simplifying (#10174)
Closes #8296. Check if types are AnyType instances after simplifying them.
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
fix variable annotation syntax (#10315)
Followup from #10255
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Issue an error when overriding typeguard with non-typeguard in subcla…
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
[mypyc] Implement dict setdefault primitive (#10286)
Related issue: mypyc/mypyc#644 Add a new primitive for dict.setdefault(). Move some dict creation primitives to beginning of dict_ops.py for better code structure.
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Use type(x) == T for type narrowing (#10284)
* Use type(x) == T for type narrowing This makes mypy use expressions like type(some_expression) == some_type for type narrowing similar to how it already does for isinstance checks. This also adds some tests to make sure that this is actually being used in type narrowing. * Avoid type narrowing in the else case `type(x) == T` is False when x is an instance of a subclass of T, which isn't the same as `isinstance(x, T)`, which checks if x is an instance of T or a subclass of T. That means that x could be a subclass of T in the else case, so we can't narrow x's type to exclude this possibility. * Move check for type(x) == T to new function Refactor code for narrowing types based on checks that look like type(x) == T into a new function * Don't narrow if multiple types found Avoid narrowing in a comparison with multiple types being compared to each other even if there is a type(x) call being compared to one of them. * Avoid narrowing if no type calls found Return early if we haven't found any calls to type * Fix type signature and documentation * Add type is not equal tests Add tests to make sure that type(x) != T and type(x) is not T work as expected (the same as type(x) == T and type(x) is T but with the if and else branches switched. Currently the type(x) != T check is failing because of a mypy error about an unsupported left operand type. * Fix "Unsupported left operand type" error in tests Add fixtures to some of the tests to make mypy not show an error when we try to compare types * Narrow types in else case if type is final Final types cannot be subclassed, so it's impossible for a subclass of a final type to be used in the else case of a comparison of type(x) to a final type. That means we can narrow types in the else case the same way we would do for isinstance checks if type(x) is being compared to a final type.
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits
Commits on Apr 11, 2021
-
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Update extending_mypy.rst (#10222)
Two things I have changed: 1. `get_function_signature_hook` was missing from docs, but it is defined https://github.com/python/mypy/blob/ac66403cb4374b858786350b96e7f5972db84bcd/mypy/plugin.py#L368-L376 2. While reading the docs, this `UserDefined` for `get_class_decorator_hook` example caught my eye. It was not clear how `UserDefined` and `@customize` work. I believe that `@dataclass` example is better for two reasons. First, it is an existing API and is already familiar to our users. Secondly, there's an actual plugin for it, so people can see how it is implemented
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Fix Generators typeshed test (#10255)
typshed mistakenly set itertools.count as a function while it is actually a class. Meaning that it returns a class instance and then this clashes with the filter result.
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits
Commits on Apr 8, 2021
-
Consider reversed operands order when comparing version info (#10288)
Closes #10264. Consider reversed order of operands when trying to compare version info. When reversed order is used, operator is reversed as well for correct comparison.
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
[mypyc] Only lookup vtable indices if needed for method call emits (#…
…10290) The vtable index is only needed for when we actually go through a vtable lookup. I don't believe this is actually a major performance improvement, but it should make it clearer what's important for each branch.
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits
Commits on Apr 6, 2021
-
[mypyc] Optimize truth value testing for strings (#10269)
Add a new primitive to check for empty strings. Related to mypyc/mypyc#768.
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits
Commits on Apr 5, 2021
-
Use double quotes errors 'in async function, 'Cannot determine type o…
…f' and 'syntax error in type comment' (#10282) * in async function - double quotes * Cannot determine type of - double quotes * syntax error in type comment - double quotes
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits
Commits on Apr 4, 2021
-
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits
Commits on Mar 31, 2021
-
[mypyc] Faster set creation with generator expression (#10261)
Closes mypyc/mypyc#771 and #9707. Changes: * Move code from tranform_set_comprehension to translate_set_comprehension * Fix the unnecessary set creation (#9707 (comment))
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits
Commits on Mar 29, 2021
-
stubtest: check overloads are functions, don't early return (#10258)
Fixes #10254 Co-authored-by: hauntsaninja <>
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits -
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits
Commits on Mar 28, 2021
-
This works for me locally, but the version on ReadTheDocs seems broken Co-authored-by: hauntsaninja <>
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits
Commits on Mar 27, 2021
-
[mypyc] Support class-based TypedDict definitions (#10226)
These need to be compiled as non-extension classes. Also mypy has a special internal representation for these which doesn't correspond to what's there at runtime and requires some hacks. Fixes mypyc/mypyc#803.
Verified
This commit was created on GitHub.com and signed with GitHub’s verified signature.GPG key ID: 4AEE18F83AFDEB23 Learn about signing commits