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

Inherit unspecified types from superclass #3094

Closed
Rizhiy opened this issue Feb 21, 2022 · 3 comments
Closed

Inherit unspecified types from superclass #3094

Rizhiy opened this issue Feb 21, 2022 · 3 comments
Labels
enhancement request New feature or request

Comments

@Rizhiy
Copy link

Rizhiy commented Feb 21, 2022

Is your feature request related to a problem? Please describe.
Currently, when method is overridden, we have to specify types again, even if they match the superclass. This is annoying and also against DRY principle.

Describe the solution you'd like
If a subclass implements a method which is defined in superclass and types are not specified, but otherwise the signature is an exact match, types should be inherited from superclass.

class Interface:
	def example(self,  a: str) -> int:
		raise NotImplementedError

class Implementation(Interface):
	def example(self, a):
		reveal_type(a) # Currently, 'Unknown', should be str
		# do stuff

Return type similarly have to be re-specified.

Additional context
I'm not sure how re-specified types should be treated, but I guess if any type is re-specified might as well re-specify all types.

@Rizhiy Rizhiy added the enhancement request New feature or request label Feb 21, 2022
@JelleZijlstra
Copy link
Contributor

Related mypy issue: python/mypy#3903.

@erictraut
Copy link
Collaborator

This is a duplicate of #2982.

@erictraut
Copy link
Collaborator

I will point out that I'm considering adding this functionality but primarily for completion suggestions and other language server features, not for static type checking. As I mention in the other thread, there are a bunch of edge cases where the behavior will be undefined, and I don't plan to support those cases. If you are using pyright for static type checking, I encourage you to provide complete annotations for all input parameters.

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

No branches or pull requests

3 participants