Skip to content

Commit

Permalink
Fix #214 (#1609)
Browse files Browse the repository at this point in the history
* remove test for nonconsecutive overloads

This doesn't seem to be testing what it says it is.
Nonconsecutive overloads result in a different error,
as described in #409. This test should be added to
check that behavior once it is fixed.

* fix error message for global function redefinition
  • Loading branch information
thomasballinger authored and gvanrossum committed Jun 3, 2016
1 parent 3fc6dec commit 382d925
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
6 changes: 1 addition & 5 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2209,11 +2209,7 @@ def add_local(self, node: Union[Var, FuncBase], ctx: Context) -> None:
def check_no_global(self, n: str, ctx: Context,
is_func: bool = False) -> None:
if n in self.globals:
if is_func and isinstance(self.globals[n].node, FuncDef):
self.fail(("Name '{}' already defined (overload variants "
"must be next to each other)").format(n), ctx)
else:
self.name_already_defined(n, ctx)
self.name_already_defined(n, ctx)

def name_not_defined(self, name: str, ctx: Context) -> None:
message = "Name '{}' is not defined".format(name)
Expand Down
6 changes: 5 additions & 1 deletion mypy/test/data/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ from typing import Any
x = None # type: Any
if x:
def f(): pass
def f(): pass # E: Name 'f' already defined (overload variants must be next to each other)
def f(): pass # E: Name 'f' already defined

[case testIncompatibleConditionalFunctionDefinition]
from typing import Any
Expand Down Expand Up @@ -1515,6 +1515,10 @@ def h(y): pass
f = h
f = g # E: Incompatible types in assignment (expression has type Callable[[Any, Any], Any], variable has type Callable[[Any], Any])

[case testRedefineFunction2]
def f() -> None: pass
def f() -> None: pass # E: Name 'f' already defined


-- Special cases
-- -------------
Expand Down
6 changes: 0 additions & 6 deletions mypy/test/data/check-overloading.test
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ class A:
def f(self, x: 'B') -> 'B': pass
class B: pass

[case testNonConsecutiveOverloads]
from typing import Any
def f() -> None: pass
def g() -> None: pass
def f(x: Any) -> None: pass # E: Name 'f' already defined (overload variants must be next to each other)

[case testOverloadsWithDifferentArgumentCounts]
from typing import overload
a, b = None, None # type: (A, B)
Expand Down

0 comments on commit 382d925

Please sign in to comment.