René's URL Explorer Experiment


Title: Handling mixins that reference fields that they do not contain · Issue #5837 · python/mypy · GitHub

Open Graph Title: Handling mixins that reference fields that they do not contain · Issue #5837 · python/mypy

X Title: Handling mixins that reference fields that they do not contain · Issue #5837 · python/mypy

Description: This is more of a question or a feature request if there's not a good way to do it. I'm currently adding types to existing python 2.7 code base hoping that it will help me with migrating the code to Python 3. I run into code that looks l...

Open Graph Description: This is more of a question or a feature request if there's not a good way to do it. I'm currently adding types to existing python 2.7 code base hoping that it will help me with migrating the code t...

X Description: This is more of a question or a feature request if there's not a good way to do it. I'm currently adding types to existing python 2.7 code base hoping that it will help me with migrating th...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Handling mixins that reference fields that they do not contain","articleBody":"This is more of a question or a feature request if there's not a good way to do it.\r\n\r\nI'm currently adding types to existing python 2.7 code base hoping that it will help me with migrating the code to Python 3.\r\n\r\nI run into code that looks like this:\r\n```python\r\n#! /usr/bin/env python\r\n\r\nclass A(object):\r\n\tdef __init__(self, var1, var2):\r\n\t\t# type: (str, str) -> None\r\n\t\tself.var1 = var1\r\n\t\tself.var2 = var2\r\n\r\nclass Mixin(object):\r\n\tdef funcA(self):\r\n\t\t# type: () -> str\r\n\t\treturn self.var1\r\n\r\nclass B(A, Mixin):\r\n\tpass\r\n\r\ndef main():\r\n\t# type: () -> None\r\n\r\n\ta = B('value1', 'value2')\r\n\tprint(a.funcA())\r\n\r\nif __name__ == '__main__':\r\n\tmain()\r\n```\r\n\r\nThis is valid Python code, i.e.:\r\n```\r\n$ ./test.py\r\nvalue1\r\n```\r\n\r\nBut mypy is complaining:\r\n\r\n```\r\n$ ../py37/bin/mypy --python-executable ../py27/bin/python test.py\r\ntest.py:12: error: \"Mixin\" has no attribute \"var1\"\r\n```\r\n\r\nI understand the issue, there's nothing in `Mixin` class that states that `var1` will be available.\r\n\r\nMy question is is there a way to tell mypy somehow that this attribute will be available?\r\n\r\nI did not have much luck with using abstract classes and `Protocol`.\r\nI also had a suggestion to use stub file, but that doesn't look like be perfect solution either, since I might need to define types outside of the module and keep them in sync. And this pattern is used in multiple places not just one.\r\n\r\nIs there a way how this could be expressed in mypy? If the code needs to be slightly refactored without changing how it works I suppose that might also be acceptable.\r\n","author":{"url":"https://github.com/takeda","@type":"Person","name":"takeda"},"datePublished":"2018-10-25T18:03:21Z","url":"https://github.com/python/mypy/issues/5837"}

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:cbf21b78-8bde-3e33-d6c6-1acf9b650b4e
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE366:137B3:C4CC67:FF4B9C:6AFFF16A
html-safe-nonce06daa05701a1803766d45180a1c84fa1ea05af3142b0fc46f4b02544c9705335
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzY2OjEzN0IzOkM0Q0M2NzpGRjRCOUM6NkFGRkYxNkEiLCJ2aXNpdG9yX2lkIjoiOTg0NDQ5MDA5MDM0NzE5NTk0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac1778eef46f6c012a78ab4bec1f862d74fa77405592078a311ddc989b96241b8d
hovercard-subject-tagissue:374065037
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/5837/issue_layout
twitter:imagehttps://opengraph.githubassets.com/3e43f5d5b6fcc6d2853a8dbba0ec721817daac7ee699cbe40341873f441f889c/python/mypy/issues/5837
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/3e43f5d5b6fcc6d2853a8dbba0ec721817daac7ee699cbe40341873f441f889c/python/mypy/issues/5837
og:image:altThis is more of a question or a feature request if there's not a good way to do it. I'm currently adding types to existing python 2.7 code base hoping that it will help me with migrating the code t...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametakeda
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/5837#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fmypy%2Fissues%2F5837
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%2F5837
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/5837
Reloadhttps://github.com/python/mypy/issues/5837
Reloadhttps://github.com/python/mypy/issues/5837
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/5837
New issuehttps://github.com/login?return_to=https://github.com/python/mypy/issues/5837
Handling mixins that reference fields that they do not containhttps://github.com/python/mypy/issues/5837#top
https://github.com/takeda
takedahttps://github.com/takeda
on Oct 25, 2018https://github.com/python/mypy/issues/5837#issue-374065037
https://github.com/msullivan
msullivanhttps://github.com/msullivan
on Oct 25, 2018https://github.com/python/mypy/issues/5837#issuecomment-433165353
https://github.com/takeda
takedahttps://github.com/takeda
on Oct 25, 2018https://github.com/python/mypy/issues/5837#issuecomment-433242251
https://github.com/JelleZijlstra
JelleZijlstrahttps://github.com/JelleZijlstra
on Oct 25, 2018https://github.com/python/mypy/issues/5837#issuecomment-433243772
https://github.com/takeda
takedahttps://github.com/takeda
on Oct 26, 2018https://github.com/python/mypy/issues/5837#issuecomment-433274930
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Oct 26, 2018https://github.com/python/mypy/issues/5837#issuecomment-433275180
https://github.com/takeda
takedahttps://github.com/takeda
on Oct 26, 2018https://github.com/python/mypy/issues/5837#issuecomment-433275420
takedahttps://github.com/takeda
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Oct 26, 2018https://github.com/python/mypy/issues/5837#event-1927836341
takedahttps://github.com/takeda
on Oct 26, 2018https://github.com/python/mypy/issues/5837#event-1927850615
https://github.com/takeda
takedahttps://github.com/takeda
on Oct 26, 2018https://github.com/python/mypy/issues/5837#issuecomment-433277873
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Oct 26, 2018https://github.com/python/mypy/issues/5837#issuecomment-433284202
https://github.com/takeda
takedahttps://github.com/takeda
on Oct 26, 2018https://github.com/python/mypy/issues/5837#issuecomment-433284818
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Oct 26, 2018https://github.com/python/mypy/issues/5837#issuecomment-433286973
https://www.python.org/download/releases/2.3/mro/https://www.python.org/download/releases/2.3/mro/
https://github.com/takeda
takedahttps://github.com/takeda
on Oct 26, 2018https://github.com/python/mypy/issues/5837#issuecomment-433291307
https://github.com/gvanrossum
gvanrossumhttps://github.com/gvanrossum
on Oct 26, 2018https://github.com/python/mypy/issues/5837#issuecomment-433479298
gvanrossumhttps://github.com/gvanrossum
completedhttps://github.com/python/mypy/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Oct 26, 2018https://github.com/python/mypy/issues/5837#event-1929376999
kdrag0nhttps://github.com/kdrag0n
on Dec 15, 2019https://github.com/python/mypy/issues/5837#event-2883806737
bot: Split into multiple compartmentalized ABC mixinshttps://github.com/kdrag0n/pyrobud/commit/6edfb6255eba33b8aa7530ca860f413c58834997
6edfb62https://github.com/kdrag0n/pyrobud/commit/6edfb6255eba33b8aa7530ca860f413c58834997
alegonzhttps://github.com/alegonz
on Jan 8, 2020https://github.com/python/mypy/issues/5837#event-2931550207
Handle missing attribute in mixin properly in type-checkhttps://github.com/alegonz/baikal/commit/9de8e83176887a3cb9c14e183081b3601ea3904a
9de8e83https://github.com/alegonz/baikal/commit/9de8e83176887a3cb9c14e183081b3601ea3904a
https://github.com/leonardoramirezr
leonardoramirezrhttps://github.com/leonardoramirezr
on Jul 9, 2020https://github.com/python/mypy/issues/5837#issuecomment-656346792
https://github.com/jaredlockhart
jaredlockharthttps://github.com/jaredlockhart
on Jul 21, 2020https://github.com/python/mypy/issues/5837#issuecomment-661619338
#6372https://github.com/python/mypy/issues/6372
https://github.com/jsatt
jsatthttps://github.com/jsatt
on Jul 28, 2020https://github.com/python/mypy/issues/5837#issuecomment-665309244
https://github.com/BakinSergey
BakinSergeyhttps://github.com/BakinSergey
on Aug 18, 2023https://github.com/python/mypy/issues/5837#issuecomment-1683861934
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/mypy/issues/5837
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/mypy/issues/5837
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.