(original) (raw)

On 14 January 2018 at 08:20, Chris Angelico <rosuav@gmail.com> wrote:
On Sun, Jan 14, 2018 at 7:10 PM, joannah nanjekye
<nanjekyejoannah@gmail.com> wrote:
\> Hello,
\>
\> Apparently when you implement two methods with the same name:
\>
\> def sub(x, y):
\> print(x -y)
\>
\> def sub(x, y):
\> print(x -y)
\>
\> Even with type hints.
\>
\> def sub(x: int, y:int) -> int:
\> return x - y
\>
\> def sub(x: float, y:float) -> float:
\> return 8
\>
\> If you are from another background, you will expect the syntax with type
\> hints to act as though method overloading but instead last implementation is
\> always called. If this is the required behavior,then just flag any duplicate
\> method implementations as syntax errors.
\>
\> Is this sort of method name duplication important in any cases?
\>
\> Not aimed at criticism, just to understand.

This is not an error in the language for the same reason that any
other assignment isn't an error:

x = 5
x = 6

But you will find that a number of linters will flag this as a
warning. You can configure your editor to constantly run a linter and
show you when something's wrong.

For example mypy (and probably also PyCharm) warn about variable/function/class re-definition.

--
Ivan