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

incorrect MethodRedefinitionWarning #188

Open
Wouter1 opened this issue Aug 27, 2024 · 2 comments
Open

incorrect MethodRedefinitionWarning #188

Wouter1 opened this issue Aug 27, 2024 · 2 comments

Comments

@Wouter1
Copy link

Wouter1 commented Aug 27, 2024

from __future__ import annotations
from plum import dispatch
from typing import TypeVar, Type

T=TypeVar('T')
class A:
 @dispatch
 def f(self, x:Type[T])->int:
  return 1
 @dispatch
 def f(self, x:int, y:int)->int:
  return 2


A().f(int)

This gives me

/tmp/PythonVenvs/geniusweb1targz/lib/python3.8/site-packages/plum/type.py:215: UserWarning: Could not resolve the type hint of `~T`. I have ended the resolution here to not make your code break, but some types might not be working correctly. Please open an issue at https://github.com/wesselb/plum.
  return tuple(resolve_type_hint(arg) for arg in x)
/tmp/PythonVenvs/geniusweb1targz/lib/python3.8/site-packages/plum/resolver.py:269: MethodRedefinitionWarning: `Method(function_name='f', signature=Signature(typing.Any, int, int), return_type=<class 'int'>, impl=<function A.f at 0x7fec7ec40af0>)` overwrites the earlier definition `Method(function_name='f', signature=Signature(typing.Any, int, int), return_type=<class 'int'>, impl=<function A.f at 0x7fec7ecd6af0>)`.
  warnings.warn(

This looks incorrect to me. The f;s have different number of arguments so there can never be an ambiguity

@Wouter1
Copy link
Author

Wouter1 commented Aug 27, 2024

The error message may change slightly, if I run it now I get only the first :

/tmp/PythonVenvs/geniusweb1targz/lib/python3.8/site-packages/plum/type.py:215: UserWarning: Could not resolve the type hint of `~T`. I have ended the resolution here to not make your code break, but some types might not be working correctly. Please open an issue at https://github.com/wesselb/plum.
  return tuple(resolve_type_hint(arg) for arg in x)
1

Not sure what this "type hint of ~T " means or why it's a problem.

@Wouter1
Copy link
Author

Wouter1 commented Aug 27, 2024

Maybe related to #101

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

No branches or pull requests

1 participant