René's URL Explorer Experiment


Title: Dealing with error: Signature of "func" incompatible with supertype "Base" · Issue #9174 · python/mypy · GitHub

Open Graph Title: Dealing with error: Signature of "func" incompatible with supertype "Base" · Issue #9174 · python/mypy

X Title: Dealing with error: Signature of "func" incompatible with supertype "Base" · Issue #9174 · python/mypy

Description: Hello, this is a user question. Software versions are: Python 3.6.9 mypy 0.782 mypy-0.790+dev.28829fbb684d7535680934b401c05698db5b4d85 (from GitHub) I have a question related to mypy checks of overridden methods, as documented here. From...

Open Graph Description: Hello, this is a user question. Software versions are: Python 3.6.9 mypy 0.782 mypy-0.790+dev.28829fbb684d7535680934b401c05698db5b4d85 (from GitHub) I have a question related to mypy checks of over...

X Description: Hello, this is a user question. Software versions are: Python 3.6.9 mypy 0.782 mypy-0.790+dev.28829fbb684d7535680934b401c05698db5b4d85 (from GitHub) I have a question related to mypy checks of over...

Opengraph URL: https://github.com/python/mypy/issues/9174

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Dealing with error: Signature of \"func\" incompatible with supertype \"Base\"","articleBody":"Hello,\r\n\r\nthis is a user question.\r\n\r\nSoftware versions are:\r\n\r\n* Python 3.6.9\r\n* mypy 0.782\r\n* mypy-0.790+dev.28829fbb684d7535680934b401c05698db5b4d85 (from GitHub)\r\n\r\nI have a question related to mypy checks of overridden methods, as [documented here](https://mypy.readthedocs.io/en/latest/error_code_list.html#check-validity-of-overrides-override).\r\n\r\nFrom ticket #1237 (this [comment](https://github.com/python/mypy/issues/1237#issuecomment-189490903) in particular), I understand that this is to be expected and that there are reasons behind the behaviour below.\r\n\r\nPlease consider the classes here.\r\n\r\n\r\n```python\r\n# ######################################################################\r\n\r\nclass Base:\r\n    def __init__(self):\r\n        self.a = 0\r\n        self.zxc = 'qwerty'\r\n\r\n    def func(self, a:int):\r\n        self.a = a\r\n\r\nclass ChildOne(Base):\r\n    def __init__(self):\r\n        self.b = 0\r\n\r\n    def func(self, a:int, b:int):\r\n        self.b = b\r\n        super().func(a)\r\n\r\nclass ChildTwo(Base):\r\n    def __init__(self):\r\n        self.b = 0\r\n        self.c = 0\r\n\r\n    def func(self, a:int, b:int, c:int):\r\n        self.b = b\r\n        self.c = c\r\n        super().func(a)\r\n\r\n# ######################################################################\r\n\r\nclass Base2:\r\n    def do_something(self, *args, **kwargs):\r\n        raise NotImplementedError('Should be overridden by subclasses')\r\n\r\nclass ChildOne2(Base2):\r\n    def do_something(self, arg1:int, arg2:int):\r\n        pass\r\n\r\nclass ChildTwo2(Base2):\r\n    def do_something(self, arg1:int, arg2:str, arg3:list, arg4:dict):\r\n        pass\r\n\r\n# ######################################################################\r\n```\r\n\r\nWhat mypy reports:\r\n\r\n```bash\r\n$ mypy mypy1.py\r\nmypy1.py:14: error: Signature of \"func\" incompatible with supertype \"Base\"\r\nmypy1.py:23: error: Signature of \"func\" incompatible with supertype \"Base\"\r\nmypy1.py:35: error: Signature of \"do_something\" incompatible with supertype \"Base2\"\r\nmypy1.py:39: error: Signature of \"do_something\" incompatible with supertype \"Base2\"\r\nFound 4 errors in 1 file (checked 1 source file)\r\n$\r\n```\r\n\r\n* The first case are sub-classes that have functionality on top of what the base class offers. Having performed what they are supposed to do, they forward the common parameter(s) to a parent class implementing some kind of a common functionality.\r\n\r\n    In addition to the common functionality, it is often desirable to treat instances of ChildOne and ChildTwo as though they were instances of Base because I am only interested in the fact that the 'zxc' attribute is available, no matter what particular subclass of Base it comes from.\r\n\r\n* The other situation is considered the same type of an error by mypy in the sense that it is a case of differing signatures, which is why I am providing it here in the same ticket but conceptually it is somewhat different - I find myself writing this kind of code with plugins-like architectures where there is a set of methods to implement but sub-classes know better what their actual arguments and return types are.\r\n\r\nIn either case, this is not really about the child classes arguments that are wider or narrower in the mypy's type checking sense which I recognise is yet another situation.\r\n\r\nI find mypy a great tool and I am very thankful for your effort. However, I am just not sure how to tackle the two scenarios above, how to specify the types here.\r\n\r\nIn the latter scenario, I think it would suffice if I could just skip type checking in Base2's ```do_something``` method, after all it is not doing anything with its input, but using ```# type: ignore``` still leads to the same error.\r\n\r\n```python\r\n    def do_something(self, *args, **kwargs):\r\n        # type: ignore\r\n        raise NotImplementedError('Should be overridden by subclasses')\r\n```\r\n\r\nIn the former case, I would truly like for the right types to be checked. In such a simple case, I could possibly simply rename func to base_func and call that in sub-classes but with a hierarchy that was deeper it could become difficult to know which base method to call thus being able to do simply ```super().func(a)``` and have it bubble up wherever the receiver is, that would be most convenient.\r\n\r\nJust to confirm it, I realise why mypy behaves in that way by default as this code looks like; I am just looking for a way to configure it to type check it anyway somehow because it seems a reasonable use-case, especially because I read comments in #1237 as confirming my belief to a degree (the idea of @covariant_args).\r\n\r\nThank you for your assistance.","author":{"url":"https://github.com/dsuch","@type":"Person","name":"dsuch"},"datePublished":"2020-07-19T23:43:56Z","url":"https://github.com/python/mypy/issues/9174"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:444a169e-65aa-4293-a492-0d22e1c8da5b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9F8A:1A1C04:18ECAF8:21B738F:6AFFF693
html-safe-noncefcd212ca3777d50e2250c725f3169e3b0251006c03c89a97699de61ee9ad8e70
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjhBOjFBMUMwNDoxOEVDQUY4OjIxQjczOEY6NkFGRkY2OTMiLCJ2aXNpdG9yX2lkIjoiMTEwNzAwMTYzOTE5NTA5MTM5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac93d420373da167869973d1b43ad397e423c18d526ceb070750fde2418c49cc5b
hovercard-subject-tagissue:661170406
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/mypy/9174/issue_layout
twitter:imagehttps://opengraph.githubassets.com/fdfbc95be1bb404a1eb470ef4b541c5f2ce965d53c0271a184a36a33af9f6dcd/python/mypy/issues/9174
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/fdfbc95be1bb404a1eb470ef4b541c5f2ce965d53c0271a184a36a33af9f6dcd/python/mypy/issues/9174
og:image:altHello, this is a user question. Software versions are: Python 3.6.9 mypy 0.782 mypy-0.790+dev.28829fbb684d7535680934b401c05698db5b4d85 (from GitHub) I have a question related to mypy checks of over...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedsuch
hostnamegithub.com
expected-hostnamegithub.com
None0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729
turbo-cache-controlno-preview
go-importgithub.com/python/mypy git https://github.com/python/mypy.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id7053637
octolytics-dimension-repository_nwopython/mypy
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id7053637
octolytics-dimension-repository_network_root_nwopython/mypy
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release16a11879678aaf97e2a42c33ee70830aa084fa37
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/mypy/issues/9174#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F9174
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F9174
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fmypy
Reloadhttps://github.com/python/mypy/issues/9174
Reloadhttps://github.com/python/mypy/issues/9174
Reloadhttps://github.com/python/mypy/issues/9174
pythonhttps://github.com/python
mypyhttps://github.com/python/mypy
Codehttps://github.com/python/mypy
Issues2.7k (2.7k)https://github.com/python/mypy/issues
Pull requests547 (547)https://github.com/python/mypy/pulls
Actionshttps://github.com/python/mypy/actions
Projectshttps://github.com/python/mypy/projects
Wikihttps://github.com/python/mypy/wiki
Security and qualityhttps://github.com/python/mypy/security
Insightshttps://github.com/python/mypy/insights
https://github.com/python/mypy
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/9174
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/9174
Dealing with error: Signature of "func" incompatible with supertype "Base"https://github.com/python/mypy/issues/9174#top
https://github.com/dsuch
dsuchhttps://github.com/dsuch
on Jul 19, 2020https://github.com/python/mypy/issues/9174#issue-661170406
documented herehttps://mypy.readthedocs.io/en/latest/error_code_list.html#check-validity-of-overrides-override
#1237https://github.com/python/mypy/issues/1237
commenthttps://github.com/python/mypy/issues/1237#issuecomment-189490903
#1237https://github.com/python/mypy/issues/1237
https://github.com/ilevkivskyi
ilevkivskyihttps://github.com/ilevkivskyi
on Aug 3, 2020https://github.com/python/mypy/issues/9174#issuecomment-667842183
#5876https://github.com/python/mypy/issues/5876
ilevkivskyihttps://github.com/ilevkivskyi
Make any callable compatible with (*args: Any, **kwargs: Any)? #5876https://github.com/python/mypy/issues/5876
on Aug 3, 2020https://github.com/python/mypy/issues/9174#event-3614511070
ilevkivskyihttps://github.com/ilevkivskyi
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Aug 3, 2020https://github.com/python/mypy/issues/9174#event-3614511086
https://github.com/NeilGirdhar
NeilGirdharhttps://github.com/NeilGirdhar
on Jun 17, 2022https://github.com/python/mypy/issues/9174#issuecomment-1158311760
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/9174
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/9174
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.