From c819a9fc1fc4bbf9c5923854bfa7a6913a2dab7c Mon Sep 17 00:00:00 2001 From: David Shea Date: Jan 28 2016 19:48:58 +0000 Subject: Sync to latest upstream: - Generalize yield statement function type - Avoid crash on outrageous non-ASCII characters. - No longer need to pin flake8 version. - Find partial types anywhere in the stack. (removes local patch) - Update license year range to 2016 - If a base class is Any, don't get default constructor signature from object. - Simplify union types when determining type sameness - Generator fixup - Add line number to "__init__ must return None" error - Fix empty yield error in unannotated functions - Fix "except (E1, E2):" parsing in PY2. - Don't crash if no source files were found in a directory or package. - Fail without traceback when duplicate module name encountered. - Fix subtype check between generic class and Callable - Avoid crash on "x in y" where y has a partial type. - Fix type inference issue with dict(x=[], y=[]) - Fix #1160 (bogus error message) - Fix function definition within for statement --- diff --git a/.gitignore b/.gitignore index edbc1e0..ed4db8b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /mypy-0.2.0-5559de4.tar.gz /mypy-0.2.0-cd96f02.tar.gz /mypy-0.2.0-4127a66.tar.gz +/mypy-0.2.0-9befcc7.tar.gz diff --git a/0004-Find-partial-types-anywhere-in-the-stack.-Fixes-1126.patch b/0004-Find-partial-types-anywhere-in-the-stack.-Fixes-1126.patch deleted file mode 100644 index 34f9e59..0000000 --- a/0004-Find-partial-types-anywhere-in-the-stack.-Fixes-1126.patch +++ /dev/null @@ -1,144 +0,0 @@ -From 4b7951be5b9b05bdc0a577034edf15fe4ebd2940 Mon Sep 17 00:00:00 2001 -From: Guido van Rossum -Date: Thu, 14 Jan 2016 18:44:05 -0800 -Subject: [PATCH 4/4] Find partial types anywhere in the stack. Fixes #1126. - ---- - mypy/checker.py | 32 +++++++++++++++++++------------- - mypy/checkexpr.py | 14 +++++--------- - mypy/test/data/check-inference.test | 17 ++++++++++++++++- - 3 files changed, 40 insertions(+), 23 deletions(-) - -diff --git a/mypy/checker.py b/mypy/checker.py -index 2086275..ae879a2 100644 ---- a/mypy/checker.py -+++ b/mypy/checker.py -@@ -464,9 +464,11 @@ class TypeChecker(NodeVisitor[Type]): - if isinstance(orig_type, PartialType): - if orig_type.type is None: - # Ah this is a partial type. Give it the type of the function. -- defn.original_def.type = new_type -- partial_types = self.partial_types[-1] -- del partial_types[defn.original_def] -+ var = defn.original_def -+ partial_types = self.find_partial_types(var) -+ if partial_types is not None: -+ var.type = new_type -+ del partial_types[var] - else: - # Trying to redefine something like partial empty list as function. - self.fail(messages.INCOMPATIBLE_REDEFINITION, defn) -@@ -1016,9 +1018,11 @@ class TypeChecker(NodeVisitor[Type]): - # None initializers preserve the partial None type. - return - if is_valid_inferred_type(rvalue_type): -- lvalue_type.var.type = rvalue_type -- partial_types = self.partial_types[-1] -- del partial_types[lvalue_type.var] -+ var = lvalue_type.var -+ partial_types = self.find_partial_types(var) -+ if partial_types is not None: -+ var.type = rvalue_type -+ del partial_types[var] - # Try to infer a partial type. No need to check the return value, as - # an error will be reported elsewhere. - self.infer_partial_type(lvalue_type.var, lvalue, rvalue_type) -@@ -1376,14 +1380,10 @@ class TypeChecker(NodeVisitor[Type]): - def try_infer_partial_type_from_indexed_assignment( - self, lvalue: IndexExpr, rvalue: Node) -> None: - # TODO: Should we share some of this with try_infer_partial_type? -- partial_types = self.partial_types[-1] -- if not partial_types: -- # Fast path leave -- no partial types in the current scope. -- return - if isinstance(lvalue.base, RefExpr): -- var = lvalue.base.node -- if var in partial_types: -- var = cast(Var, var) -+ var = cast(Var, lvalue.base.node) -+ partial_types = self.find_partial_types(var) -+ if partial_types is not None: - typename = cast(Instance, var.type).type.fullname() - if typename == 'builtins.dict': - # TODO: Don't infer things twice. -@@ -2147,6 +2147,12 @@ class TypeChecker(NodeVisitor[Type]): - self.msg.fail(messages.NEED_ANNOTATION_FOR_VAR, context) - var.type = AnyType() - -+ def find_partial_types(self, var: Var) -> Optional[Dict[Var, Context]]: -+ for partial_types in reversed(self.partial_types): -+ if var in partial_types: -+ return partial_types -+ return None -+ - def is_within_function(self) -> bool: - """Are we currently type checking within a function? - -diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py -index 4b0cfac..e70faf3 100644 ---- a/mypy/checkexpr.py -+++ b/mypy/checkexpr.py -@@ -80,8 +80,8 @@ class ExpressionChecker: - if not lvalue: - result = NoneTyp() - else: -- partial_types = self.chk.partial_types[-1] -- if node in partial_types: -+ partial_types = self.chk.find_partial_types(node) -+ if partial_types is not None: - context = partial_types[node] - self.msg.fail(messages.NEED_ANNOTATION_FOR_VAR, context) - result = AnyType() -@@ -141,14 +141,10 @@ class ExpressionChecker: - } - - def try_infer_partial_type(self, e: CallExpr) -> None: -- partial_types = self.chk.partial_types[-1] -- if not partial_types: -- # Fast path leave -- no partial types in the current scope. -- return - if isinstance(e.callee, MemberExpr) and isinstance(e.callee.expr, RefExpr): -- var = e.callee.expr.node -- if var in partial_types: -- var = cast(Var, var) -+ var = cast(Var, e.callee.expr.node) -+ partial_types = self.chk.find_partial_types(var) -+ if partial_types is not None: - partial_type_type = cast(PartialType, var.type).type - if partial_type_type is None: - # A partial None type -> can't infer anything. -diff --git a/mypy/test/data/check-inference.test b/mypy/test/data/check-inference.test -index 525fba5..7b6438c 100644 ---- a/mypy/test/data/check-inference.test -+++ b/mypy/test/data/check-inference.test -@@ -1183,7 +1183,7 @@ b[{}] = 1 - [out] - - [case testInferDictInitializedToEmptyAndUpdatedFromMethod] --map = {} # E: Need type annotation for variable -+map = {} - def add(): - map[1] = 2 - [builtins fixtures/dict.py] -@@ -1315,3 +1315,18 @@ class A: - self.x() - [out] - main: note: In member "f" of class "A": -+ -+[case testGlobalInitializedToNoneSetFromFunction] -+a = None -+def f(): -+ global a -+ a = 42 -+[out] -+ -+[case testGlobalInitializedToNoneSetFromMethod] -+a = None -+class C: -+ def m(self): -+ global a -+ a = 42 -+[out] --- -2.7.0 - diff --git a/python3-mypy.spec b/python3-mypy.spec index 92b1d38..472ca04 100644 --- a/python3-mypy.spec +++ b/python3-mypy.spec @@ -1,9 +1,9 @@ -%global checkout 4127a66 +%global checkout 9befcc7 Name: python3-mypy # Last actual version was 0.2.0, which is 7805b2c, continues as 0.2.0_dev Version: 0.2.0 -Release: 1.dev20160115git%{?dist} +Release: 1.dev20160128git%{?dist} Summary: A static type checker for Python %{?python_provide:%python_provide python3-mypy} @@ -11,7 +11,7 @@ Summary: A static type checker for Python # package does not include those files License: MIT URL: https://github.com/JukkaL/mypy -# git archive --prefix=mypy-0.2.0-4127a66/ 4127a66 | gzip -c9 > mypy-0.2.0-4127a66.tar.gz +# git archive --prefix=mypy-0.2.0-9befcc7/ 9befcc7 | gzip -c9 > mypy-0.2.0-9befcc7.tar.gz Source0: mypy-%{version}-%{checkout}.tar.gz # The bundled typing.py is not needed with python 3.5 @@ -24,9 +24,6 @@ Patch1: 0002-Look-for-typeshed-in-usr-share.patch # patch 1 breaks the data dir lookup when called as /bin/mypy instead of /usr/bin/mypy Patch3: 0003-Canonicalize-bin_dir-when-looking-for-data_dir.patch -# from https://github.com/JukkaL/mypy/issues/1126 -Patch4: 0004-Find-partial-types-anywhere-in-the-stack.-Fixes-1126.patch - BuildRequires: python3-devel # Needed to generate the man pages @@ -77,6 +74,26 @@ PYTHONPATH=%{buildroot}%{python3_sitelib} \ %{_prefix}/lib/mypy %changelog +* Thu Jan 28 2016 David Shea - 0.2.0-1.dev20160128git +- Generalize yield statement function type +- Avoid crash on outrageous non-ASCII characters. +- No longer need to pin flake8 version. +- Find partial types anywhere in the stack. (removes local patch) +- Update license year range to 2016 +- If a base class is Any, don't get default constructor signature from object. +- Simplify union types when determining type sameness +- Generator fixup +- Add line number to "__init__ must return None" error +- Fix empty yield error in unannotated functions +- Fix "except (E1, E2):" parsing in PY2. +- Don't crash if no source files were found in a directory or package. +- Fail without traceback when duplicate module name encountered. +- Fix subtype check between generic class and Callable +- Avoid crash on "x in y" where y has a partial type. +- Fix type inference issue with dict(x=[], y=[]) +- Fix #1160 (bogus error message) +- Fix function definition within for statement + * Fri Jan 15 2016 David Shea - 0.2.0-1.dev20160115git - Fix the order in which builtins are loaded. - Fix crash on undefined variable actual_types in check_argument_count (replaces local patch) diff --git a/sources b/sources index ad4504d..27d9ed1 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -1484471efd29408b2cd60c374713c7ed mypy-0.2.0-4127a66.tar.gz +dd79f078ab074058e340eeec031cf3af mypy-0.2.0-9befcc7.tar.gz