[issue42812] @overload-ing method of parent class without actual implementation

2021-01-02 Thread Chaim Gewirtz


New submission from Chaim Gewirtz :

Why should @overload need to be followed by an implementation when an 
implementation already exists in the parent class?

Illustrative example:

class Parent:
def foo(**kwargs):
"""Argument names of foo vary depending on the child class."""

class Child(Parent):
@overload foo(a, b): ...

Raises:

"NotImplementedError: You should not call an overloaded function. A series of 
@overload-decorated functions outside a stub module should always be followed 
by an implementation that is not @overload-ed."

--
messages: 384255
nosy: chaim422
priority: normal
severity: normal
status: open
title: @overload-ing method of parent class without actual implementation
type: enhancement
versions: Python 3.10

___
Python tracker 
<https://bugs.python.org/issue42812>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42812] @overload-ing method of parent class without actual implementation

2021-01-03 Thread Chaim Gewirtz


Chaim Gewirtz  added the comment:

"The purpose of `@overload` is quite different." So, this would overload the 
@overload decorator. Hmmm...

Is there a better way to accomplish this goal? What would you suggest, a new 
decorator?

--

___
Python tracker 
<https://bugs.python.org/issue42812>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42812] @overload-ing method of parent class without actual implementation

2021-01-03 Thread Chaim Gewirtz


Chaim Gewirtz  added the comment:

To clarify, this is how it's being done now a dozen times in actual production 
code:

class Child(Parent):
@overload foo(a, b): ...
def overload(**kwargs):
return super().foo(**kwargs)

The goal of this proposed enhancement is to remove two extra lines of code per 
Child class.

--

___
Python tracker 
<https://bugs.python.org/issue42812>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42812] @overload-ing method of parent class without actual implementation

2021-01-03 Thread Chaim Gewirtz


Chaim Gewirtz  added the comment:

Interesting. PyCharm has no problem with this code. It also autocompletes the 
argument names for me, which is very useful, especially since there a dozen 
different Child classes.

Isn't "Simple is better than complex", and doesn't "...practicality beat 
purity"?

--

___
Python tracker 
<https://bugs.python.org/issue42812>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42812] @overload-ing method of parent class without actual implementation

2021-01-03 Thread Chaim Gewirtz


Chaim Gewirtz  added the comment:

What is better?

A. Keeping Python as is, with four separate signature declarations (1x Parent, 
2x @overload Child, and 1x actual signature in Child), and a second method call 
overhead at runtime (to satisfy mypy as it exists now).

--or--

B. Simplify Python to allow just two signature declarations and no extra 
overhead? 

--or--

C. Something else? Please specify.

--

___
Python tracker 
<https://bugs.python.org/issue42812>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42812] @overload-ing method of parent class without actual implementation

2021-01-03 Thread Chaim Gewirtz


Chaim Gewirtz  added the comment:

In your example, does Child foo call Parent foo? Because the intent is to use 
the parent's foo method.

--

___
Python tracker 
<https://bugs.python.org/issue42812>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42812] @overload-ing method of parent class without actual implementation

2021-01-03 Thread Chaim Gewirtz


Chaim Gewirtz  added the comment:

Thanks for your perspective.

To summarize here is how my proposed enhancement might look in practice:

class Parent:
def foo(self, **kwargs):
"""Argument names of foo vary depending on the child class."""


class Child(Parent):
@overload
def foo(self, a, b):
pass

--

___
Python tracker 
<https://bugs.python.org/issue42812>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com