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

Error with methods defined as function references wrapped in staticmethod() #5530

Open
jleclanche opened this issue Aug 27, 2018 · 1 comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal

Comments

@jleclanche
Copy link

jleclanche commented Aug 27, 2018

def foo(key: str) -> str:
	return key


class A:
	@staticmethod
	def foobar(key: str) -> str:
		return "hello world"


class B(A):
	foobar = staticmethod(foo)

This yields the following error on B.foobar:

error:Incompatible types in assignment (expression has type "staticmethod", base class "A" defined the type as "Callable[[str], str]")

@ilevkivskyi
Copy link
Member

I am quite this was already reported, but can't find the issue. The point is that mypy checks superclass compatibility before descriptors are resolved. Btw stubs for staticmethod etc. are quite basic in typeshed (mostly because mypy treats them via some special-casing when they are used as decorators) ideally I would make them generic in the wrapped function so that __get__ can return the same callable, instead of just function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal
Projects
None yet
Development

No branches or pull requests

2 participants