Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make operator overloading overlapping checks more lenient #1264

Closed
JukkaL opened this issue Mar 2, 2016 · 1 comment
Closed

Make operator overloading overlapping checks more lenient #1264

JukkaL opened this issue Mar 2, 2016 · 1 comment

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Mar 2, 2016

Currently the overlapping checks for __add__ / __radd__ and similar make it impossible to have reasonable types for the fractions std lib module (and probably also numbers).

There are several potential related issues:

  • If a base class has a dynamically typed operator method and it gets overridden with an annotated method, mypy may get confused (it shouldn't complain about dynamically typed methods).
  • The overlapping checks should perhaps not complain if multiple inheritance can break type safety, as if we do this we'll have to reject way too much basically valid code (or the checks become so complicated that it's difficult to give useful feedback for users).
  • We'll probably have to allow more flexibility around overriding overloaded functions so that a subclass can introduce new overload variants with fewer restrictions.
  • Overriding methods that use type variables with enumerated values may also be broken in cases where a subclass uses a different set of values.

This is just a placeholder issue -- I'll add more detail later. Perhaps create separate issues for all the above issues.

@gvanrossum gvanrossum added this to the Undetermined priority milestone Apr 7, 2016
mkurek pushed a commit to mkurek/typeshed that referenced this issue Dec 21, 2016
Improve operator methods for dateutil.relativedelta stubs:
* `__add__` operator method could return other types than `relativedelta` (`datetime.date` or `datetime.datetime`)
* use specific types of operators args instead of Any
* mypy currently does not handle `Union` in op methods (see python/mypy#2129, python/mypy#1442, python/mypy#1264 for details), so I've overloaded it directly
ambv pushed a commit to python/typeshed that referenced this issue Dec 28, 2016
Improve operator methods for dateutil.relativedelta stubs:
* `__add__` operator method could return other types than `relativedelta` (`datetime.date` or `datetime.datetime`)
* use specific types of operators args instead of Any
* mypy currently does not handle `Union` in op methods (see python/mypy#2129, python/mypy#1442, python/mypy#1264 for details), so I've overloaded it directly
@gvanrossum gvanrossum removed this from the Undetermined priority milestone Mar 29, 2017
@ilevkivskyi
Copy link
Member

I think all issues here are now resolved. We can open new issues if some complains about too strict overload checks will appear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants