From 8600e1ba2f9d1a179d8bbedcdbad72600fdddfd5 Mon Sep 17 00:00:00 2001 From: David Shea Date: Jan 15 2016 14:18:40 +0000 Subject: Update to latest git and add one extra patch: - Fix the order in which builtins are loaded. - Fix crash on undefined variable actual_types in check_argument_count (replaces local patch) - Fixes for Generator support - Fix crash in check_overlapping_op_methods - Hopeful fix for #1002 (lxml trouble) - No longer need to pin flake8 version. - Find partial types anywhere in the stack. (not yet committed upstream) --- diff --git a/.gitignore b/.gitignore index 0a70012..edbc1e0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /mypy-0.2.0-2736e25.tar.gz /mypy-0.2.0-5559de4.tar.gz /mypy-0.2.0-cd96f02.tar.gz +/mypy-0.2.0-4127a66.tar.gz diff --git a/0001-Do-not-install-typing.py.patch b/0001-Do-not-install-typing.py.patch index 921b088..b473eee 100644 --- a/0001-Do-not-install-typing.py.patch +++ b/0001-Do-not-install-typing.py.patch @@ -1,7 +1,7 @@ -From 1c9e9abb0200d60399d3587d2e9d070d4ede4381 Mon Sep 17 00:00:00 2001 +From 42498a957f88bdd9a956508453b651d0d9b99f98 Mon Sep 17 00:00:00 2001 From: David Shea Date: Tue, 15 Dec 2015 10:06:52 -0500 -Subject: [PATCH 1/4] Do not install typing.py +Subject: [PATCH 1/3] Do not install typing.py This module is not needed with Python 3.5 --- @@ -22,5 +22,5 @@ index 7ac47a7..8687c58 100644 packages=['mypy'], scripts=['scripts/mypy', 'scripts/stubgen'], -- -2.6.4 +2.7.0 diff --git a/0002-Look-for-typeshed-in-usr-share.patch b/0002-Look-for-typeshed-in-usr-share.patch index a3ebc6f..54df3ab 100644 --- a/0002-Look-for-typeshed-in-usr-share.patch +++ b/0002-Look-for-typeshed-in-usr-share.patch @@ -1,14 +1,14 @@ -From 80d4b998898c7ab308ae07ff7ee6e0b020f6d172 Mon Sep 17 00:00:00 2001 +From bc66f0e202f5f2b432cd8a5b8829da61962ad88b Mon Sep 17 00:00:00 2001 From: David Shea Date: Tue, 15 Dec 2015 14:01:55 -0500 -Subject: [PATCH 2/4] Look for typeshed in /usr/share +Subject: [PATCH 2/3] Look for typeshed in /usr/share --- mypy/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/build.py b/mypy/build.py -index 11705df..2c54225 100644 +index edb3896..0f5efdc 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -221,7 +221,7 @@ def default_data_dir(bin_dir: str) -> str: @@ -21,5 +21,5 @@ index 11705df..2c54225 100644 # Assume we installed python3 with brew on os x return os.path.join(os.path.dirname(dir), 'lib', 'mypy') -- -2.6.4 +2.7.0 diff --git a/0003-Canonicalize-bin_dir-when-looking-for-data_dir.patch b/0003-Canonicalize-bin_dir-when-looking-for-data_dir.patch new file mode 100644 index 0000000..6eabf07 --- /dev/null +++ b/0003-Canonicalize-bin_dir-when-looking-for-data_dir.patch @@ -0,0 +1,29 @@ +From e404b6d1545fba08859cd4f3de49367ca99792ec Mon Sep 17 00:00:00 2001 +From: David Shea +Date: Thu, 7 Jan 2016 10:02:27 -0500 +Subject: [PATCH 3/3] Canonicalize bin_dir when looking for data_dir. + +This way calling mypy as /bin/mypy will look for the data dir starting +in /usr instead of /. +--- + mypy/build.py | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/mypy/build.py b/mypy/build.py +index 0f5efdc..156a92f 100644 +--- a/mypy/build.py ++++ b/mypy/build.py +@@ -210,6 +210,10 @@ def default_data_dir(bin_dir: str) -> str: + if not bin_dir: + # Default to directory containing this file's parent. + return os.path.dirname(os.path.dirname(__file__)) ++ ++ # Canonicalize the path in case bin_dir is a symlink ++ bin_dir = os.path.realpath(bin_dir) ++ + base = os.path.basename(bin_dir) + dir = os.path.dirname(bin_dir) + if (sys.platform == 'win32' and base.lower() == 'scripts' +-- +2.7.0 + diff --git a/0003-Fix-1095.-Look-for-the-keyword-type-in-the-right-pla.patch b/0003-Fix-1095.-Look-for-the-keyword-type-in-the-right-pla.patch deleted file mode 100644 index 2fbff6f..0000000 --- a/0003-Fix-1095.-Look-for-the-keyword-type-in-the-right-pla.patch +++ /dev/null @@ -1,27 +0,0 @@ -From fddb3482039c6fb23fd223ffa1976483209a72db Mon Sep 17 00:00:00 2001 -From: David Shea -Date: Mon, 4 Jan 2016 13:19:43 -0500 -Subject: [PATCH 3/4] Fix #1095. Look for the keyword type in the right place. - -From https://github.com/JukkaL/mypy/issues/1095#issuecomment-166725598 ---- - mypy/checkexpr.py | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py -index 23d3fa0..7c45cc0 100644 ---- a/mypy/checkexpr.py -+++ b/mypy/checkexpr.py -@@ -542,7 +542,8 @@ class ExpressionChecker: - nodes.ARG_NAMED] and is_duplicate_mapping( - formal_to_actual[i], actual_kinds): - if (self.chk.typing_mode_full() or -- isinstance(actual_type, TupleType)): -+ (i < len(actual_types) and -+ isinstance(actual_types[i], TupleType))): - self.msg.duplicate_argument_value(callee, i, context) - elif (kind == nodes.ARG_NAMED and formal_to_actual[i] and - actual_kinds[formal_to_actual[i][0]] != nodes.ARG_NAMED): --- -2.6.4 - diff --git a/0004-Canonicalize-bin_dir-when-looking-for-data_dir.patch b/0004-Canonicalize-bin_dir-when-looking-for-data_dir.patch deleted file mode 100644 index bd97edc..0000000 --- a/0004-Canonicalize-bin_dir-when-looking-for-data_dir.patch +++ /dev/null @@ -1,29 +0,0 @@ -From c12dedd6d7934ca1698a66f848cd057bbf10bbee Mon Sep 17 00:00:00 2001 -From: David Shea -Date: Thu, 7 Jan 2016 10:02:27 -0500 -Subject: [PATCH 4/4] Canonicalize bin_dir when looking for data_dir. - -This way calling mypy as /bin/mypy will look for the data dir starting -in /usr instead of /. ---- - mypy/build.py | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/mypy/build.py b/mypy/build.py -index 2c54225..76c3326 100644 ---- a/mypy/build.py -+++ b/mypy/build.py -@@ -210,6 +210,10 @@ def default_data_dir(bin_dir: str) -> str: - if not bin_dir: - # Default to directory containing this file's parent. - return os.path.dirname(os.path.dirname(__file__)) -+ -+ # Canonicalize the path in case bin_dir is a symlink -+ bin_dir = os.path.realpath(bin_dir) -+ - base = os.path.basename(bin_dir) - dir = os.path.dirname(bin_dir) - if (sys.platform == 'win32' and base.lower() == 'scripts' --- -2.6.4 - 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 new file mode 100644 index 0000000..34f9e59 --- /dev/null +++ b/0004-Find-partial-types-anywhere-in-the-stack.-Fixes-1126.patch @@ -0,0 +1,144 @@ +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 f67c11f..92b1d38 100644 --- a/python3-mypy.spec +++ b/python3-mypy.spec @@ -1,9 +1,9 @@ -%global checkout cd96f02 +%global checkout 4127a66 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.dev20160111git%{?dist} +Release: 1.dev20160115git%{?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-cd96f02/ cd96f02 | gzip -c9 > mypy-0.2.0-cd96f02.tar.gz +# git archive --prefix=mypy-0.2.0-4127a66/ 4127a66 | gzip -c9 > mypy-0.2.0-4127a66.tar.gz Source0: mypy-%{version}-%{checkout}.tar.gz # The bundled typing.py is not needed with python 3.5 @@ -21,11 +21,11 @@ Patch0: 0001-Do-not-install-typing.py.patch # bundled version Patch1: 0002-Look-for-typeshed-in-usr-share.patch -# From https://github.com/JukkaL/mypy/issues/1095#issuecomment-166725598 -Patch2: 0003-Fix-1095.-Look-for-the-keyword-type-in-the-right-pla.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 -# patch 2 breaks the data dir lookup when called as /bin/mypy instead of /usr/bin/mypy -Patch3: 0004-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 @@ -77,6 +77,15 @@ PYTHONPATH=%{buildroot}%{python3_sitelib} \ %{_prefix}/lib/mypy %changelog +* 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) +- Fixes for Generator support +- Fix crash in check_overlapping_op_methods +- Hopeful fix for #1002 (lxml trouble) +- No longer need to pin flake8 version. +- Find partial types anywhere in the stack. (not yet committed upstream) + * Mon Jan 11 2016 David Shea - 0.2.0-1.dev20160111git - Add support for more kinds of function redefinition - Allow conditionally assigning None to a module diff --git a/sources b/sources index 7a72406..ad4504d 100644 --- a/sources +++ b/sources @@ -1 +1 @@ -d707aa0c543cdf2eeb832b26d956dcb1 mypy-0.2.0-cd96f02.tar.gz +1484471efd29408b2cd60c374713c7ed mypy-0.2.0-4127a66.tar.gz