René's URL Explorer Experiment


Title: Add stubs for WTForms by Daverball · Pull Request #10557 · python/typeshed · GitHub

Open Graph Title: Add stubs for WTForms by Daverball · Pull Request #10557 · python/typeshed

X Title: Add stubs for WTForms by Daverball · Pull Request #10557 · python/typeshed

Description: This one's a bit of a doozy. I had already attempted to create stubs for this a few years back and gave up because they ended up being too annoying to use since the API isn't very friendly to static analysis. But I've recently seen some examples in types-PyYAML that gave me renewed hope to attempt this and ended up with something I'm pretty happy with. It's not perfect, there are some things about the API that flat out don't work in type checkers: Field.__new__ will return by default an UnboundField which is not a subclass of Field and even if I were to make it a faux-subclass and added overloads in __new__ to make it work for the base class, I would then also need to add an overloaded __new__ to every subclass and it would also break user-defined subclasses of Field. So that's not really sustainable. What I did instead was turn Field into a faux descriptor, that will return an UnboundField when accessed from the Form class and itself when it's accessed on the instance, that should cover most use-cases and it required only one additional hacky workaround for FieldList which has to accept Field in addition to UnboundField, if we don't want to force people to manually construct UnboundField instances for type checking. Other than that I've added a few test cases for the more complex type protocols that can be passed into Field/Form such as validators, widget and filters since it was a little bit tricky to ensure there would be no false negatives while still retaining some amount of type safety. I've integrated the stubs in two medium sized projects which both do some advanced things with the internals of WTForms in different ways and managed to catch a lot of the rough edges already. A slight pain point right now is that form validation cannot result in any kind of type narrowing, so you will need to manually add some assert form.field.data is not None for fields with InputRequired/DataRequired validators. It shouldn't be too big of an issue though, since in a lot of cases you should just be using form.populate_obj() rather than accessing individual field data. There also seems to be an issue with overriding Field.widget in subclasses, since it is both a ClassVar and instance variable. For some reason mypy will complain if subclasses annotate the field as _Widget[Self], even though that matches the definition on the base class, so that seems like a false positive on mypy's end to me. This should only really be relevant though for user defined fields with a custom default widget that have subclasses themselves. The docs for WTForms are pretty good and can be found here: https://wtforms.readthedocs.io/en/3.0.x/ Although it might still be quicker to just look at the source code: https://github.com/wtforms/wtforms/blob/3.0.1/src/wtforms/__init__.py

Open Graph Description: This one's a bit of a doozy. I had already attempted to create stubs for this a few years back and gave up because they ended up being too annoying to use since the API isn't very friendly ...

X Description: This one's a bit of a doozy. I had already attempted to create stubs for this a few years back and gave up because they ended up being too annoying to use since the API isn't very f...

Opengraph URL: https://github.com/python/typeshed/pull/10557

X: @github

direct link

Domain: github.com

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/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:548df795-10f8-7383-19f6-93d095d46bed
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA55C:30CC09:247340D:3153685:6B002A6F
html-safe-nonce8366ca7f68f232ac83671a61b4671bcd46a3500083a9ee2ad11f27ab93b46a88
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTVDOjMwQ0MwOToyNDczNDBEOjMxNTM2ODU6NkIwMDJBNkYiLCJ2aXNpdG9yX2lkIjoiMjA5NzA1ODQ3MzU2NDAyMjg3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac6b458a9c0eabc0880d1d82d196833dd2dd9f466265c549ace26aca92fb652231
hovercard-subject-tagpull_request:1470199014
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/typeshed/pull/10557/files
twitter:imagehttps://avatars.githubusercontent.com/u/5726519?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/5726519?s=400&v=4
og:image:altThis one's a bit of a doozy. I had already attempted to create stubs for this a few years back and gave up because they ended up being too annoying to use since the API isn't very friendly ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/typeshed git https://github.com/python/typeshed.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id31696383
octolytics-dimension-repository_nwopython/typeshed
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id31696383
octolytics-dimension-repository_network_root_nwopython/typeshed
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef3f3a43ca095cdea3abbb394112e971f9fdb94fa
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/typeshed/pull/10557/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Ftypeshed%2Fpull%2F10557%2Ffiles
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%2Ftypeshed%2Fpull%2F10557%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Ftypeshed
Reloadhttps://github.com/python/typeshed/pull/10557/files
Reloadhttps://github.com/python/typeshed/pull/10557/files
Reloadhttps://github.com/python/typeshed/pull/10557/files
pythonhttps://github.com/python
typeshedhttps://github.com/python/typeshed
Codehttps://github.com/python/typeshed
Issues196 (196)https://github.com/python/typeshed/issues
Pull requests251 (251)https://github.com/python/typeshed/pulls
Actionshttps://github.com/python/typeshed/actions
Security and qualityhttps://github.com/python/typeshed/security
Insightshttps://github.com/python/typeshed/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Ftypeshed%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Ftypeshed%2Fissues%2Fnew%2Fchoose
JelleZijlstrahttps://github.com/JelleZijlstra
python:mainhttps://github.com/python/typeshed/tree/main
Daverball:wtformshttps://github.com/Daverball/typeshed/tree/wtforms
Conversation 35 https://github.com/python/typeshed/pull/10557
Commits 11 https://github.com/python/typeshed/pull/10557/commits
Checks 0 https://github.com/python/typeshed/pull/10557/checks
Files changed https://github.com/python/typeshed/pull/10557/files
Please reload this pagehttps://github.com/python/typeshed/pull/10557/files
Add stubs for WTForms https://github.com/python/typeshed/pull/10557/files#top
Show all changes 11 commits https://github.com/python/typeshed/pull/10557/files
57ff219 Add stubs for WTForms Daverball Aug 9, 2023 https://github.com/python/typeshed/pull/10557/commits/57ff2193ec1bb203abce77b76d0db23fd38a7bdf
8a23f8d Removes redundant method override that was still untyped Daverball Aug 10, 2023 https://github.com/python/typeshed/pull/10557/commits/8a23f8d1fd79bfbf353d6b8673bc062a46f7db7b
fba94a6 Fixes pytype crash Daverball Aug 10, 2023 https://github.com/python/typeshed/pull/10557/commits/fba94a629d90c9e87a19593302a2c7c72765eeeb
6dd2253 Merge branch 'main' into wtforms JelleZijlstra Aug 10, 2023 https://github.com/python/typeshed/pull/10557/commits/6dd225351c109cd618a9984c4c126ecb72d64176
e0eb791 Fixes return type of `wtforms.form.BaseForm.errors` Daverball Aug 16, 2023 https://github.com/python/typeshed/pull/10557/commits/e0eb79182fb12d07fc429a47a977c7826392d8f0
224488a Apply suggestions from code review Daverball Sep 23, 2023 https://github.com/python/typeshed/pull/10557/commits/224488ae79bff3af483c24be89043b0f158a36a3
ee0615b Properly works around potential shadowing of `builtins.type` Daverball Sep 23, 2023 https://github.com/python/typeshed/pull/10557/commits/ee0615b444c5b1d6a659d5f000471df26a6896c2
020fae8 Adds a type alias to avoid a potentially ambiguous cyclic name reference Daverball Sep 23, 2023 https://github.com/python/typeshed/pull/10557/commits/020fae8146710e3e08b20c5712e7f7dca3babb88
28fec0b Came up with a better solution for the pytype crash Daverball Sep 23, 2023 https://github.com/python/typeshed/pull/10557/commits/28fec0bd1b6ffe51d5b8eeb423c3fb1e1e35051b
7fce4bc removes `type` that was accidentally left in Daverball Sep 23, 2023 https://github.com/python/typeshed/pull/10557/commits/7fce4bc31b3729fa7e0cc58595a8c773c9597f93
fe6d09c Improves type safety of `Form._unbound_fields` Daverball Sep 28, 2023 https://github.com/python/typeshed/pull/10557/commits/fe6d09c5c1ff5dbd0116f53d07da239c8df99d66
Clear filters https://github.com/python/typeshed/pull/10557/files
Please reload this pagehttps://github.com/python/typeshed/pull/10557/files
Please reload this pagehttps://github.com/python/typeshed/pull/10557/files
stubtest_allowlist.txt https://github.com/python/typeshed/pull/10557/files#diff-e129c41f62b855083bbcbc2c3469dec0851419f28b86238096036c5d353f61f4
check_filters.py https://github.com/python/typeshed/pull/10557/files#diff-8543ae838c3437a11b611e44a56ac4b742a9e22b5c5b9ebe22c3dcef532d064e
check_validators.py https://github.com/python/typeshed/pull/10557/files#diff-de0920565759c3e0066e39b59756528ac5d5075bd8c0a5e27d31e95248001f0e
check_widgets.py https://github.com/python/typeshed/pull/10557/files#diff-20faf28c751f575d96757288824ad3868007ba7dcab3da5734295c22202089ad
METADATA.toml https://github.com/python/typeshed/pull/10557/files#diff-4200a254b91c661c43bf068713e47910d77f47faf19be2be40a906b095a87c7a
__init__.pyi https://github.com/python/typeshed/pull/10557/files#diff-def7eab834b37707e59a9897bc438eea4c45051c7d9c9f8e8d6d81e4989935d5
__init__.pyi https://github.com/python/typeshed/pull/10557/files#diff-46d036e7aa9163aa36420938a7b8012ddc70f0faf7e13d9cc34ba3b7a11933bd
core.pyi https://github.com/python/typeshed/pull/10557/files#diff-2efdbc691c1ca536db4eedd7af3ad063fe8526c4eb10c16d0be9029a0726deda
session.pyi https://github.com/python/typeshed/pull/10557/files#diff-296af9240fe87fd8efe605a7cbde3964df03979b80190a70c029ef4daedc78ef
__init__.pyi https://github.com/python/typeshed/pull/10557/files#diff-affaf192ccb4bd6a730b221783e451f5eb220174898db1dae64e2d3c6c6a91f3
choices.pyi https://github.com/python/typeshed/pull/10557/files#diff-0602f2cf15e64d6d3b73c20c28e285a414175c4809377d01643051ae5f178eea
core.pyi https://github.com/python/typeshed/pull/10557/files#diff-f27ab8bde1be257fae40e81681125afc1d1893303aa4f3709f8a5583766e1526
datetime.pyi https://github.com/python/typeshed/pull/10557/files#diff-79be0dc05b9dd6584be8b336a07282d253697348668936c75c778f3889df4bd3
form.pyi https://github.com/python/typeshed/pull/10557/files#diff-9617b0aa573f07a9598c1c163bf8a7d97635185d7550ae7162382ce256228d6c
list.pyi https://github.com/python/typeshed/pull/10557/files#diff-16228a42430060c179c2fb427f9fe9e6c7040e0002bc718edfcb3d41c39f59a0
numeric.pyi https://github.com/python/typeshed/pull/10557/files#diff-3023de457459e5b1dac25cae62b93be03d7f1866797f2d31bc12e16b50fea076
simple.pyi https://github.com/python/typeshed/pull/10557/files#diff-d6532c4f1331ab89d0031c19a3383a001ef20b677a47cde92afe58346c77a5e6
form.pyi https://github.com/python/typeshed/pull/10557/files#diff-99c085ce451f023fe644a57d7ea2926e102634f0600a3b8500cf5955a0807afd
i18n.pyi https://github.com/python/typeshed/pull/10557/files#diff-7718793cc64bfa6dc3f31d5d317b69bbf5757522096310d10f10e742462189cb
meta.pyi https://github.com/python/typeshed/pull/10557/files#diff-c07a7cc135f18fa390d0a3cfd0c60dc5fbd1f9caa155f3a5de456548b44bc935
utils.pyi https://github.com/python/typeshed/pull/10557/files#diff-da4c64894ca1c3f28b19a023d84a1c2499f5a959b652f87816793abf37da28e4
validators.pyi https://github.com/python/typeshed/pull/10557/files#diff-cfea38d3bc882f892b49e0eaf2e34548b7de615a3906ad4493f7135548f6a6d9
__init__.pyi https://github.com/python/typeshed/pull/10557/files#diff-43bc96232c27a78b68e08c80e3707807e72e8884bb65172c6963eb2f47bce5f9
core.pyi https://github.com/python/typeshed/pull/10557/files#diff-151f64a7cb41785767a7c03213943e41bfebc93aa31843492249b27b193fa4db
stubs/WTForms/@tests/stubtest_allowlist.txthttps://github.com/python/typeshed/pull/10557/files#diff-e129c41f62b855083bbcbc2c3469dec0851419f28b86238096036c5d353f61f4
View file https://github.com/Daverball/typeshed/blob/fe6d09c5c1ff5dbd0116f53d07da239c8df99d66/stubs/WTForms/%40tests/stubtest_allowlist.txt
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/typeshed/pull/10557/{{ revealButtonHref }}
stubs/WTForms/@tests/test_cases/check_filters.pyhttps://github.com/python/typeshed/pull/10557/files#diff-8543ae838c3437a11b611e44a56ac4b742a9e22b5c5b9ebe22c3dcef532d064e
View file https://github.com/Daverball/typeshed/blob/fe6d09c5c1ff5dbd0116f53d07da239c8df99d66/stubs/WTForms/%40tests/test_cases/check_filters.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/typeshed/pull/10557/{{ revealButtonHref }}
stubs/WTForms/@tests/test_cases/check_validators.pyhttps://github.com/python/typeshed/pull/10557/files#diff-de0920565759c3e0066e39b59756528ac5d5075bd8c0a5e27d31e95248001f0e
View file https://github.com/Daverball/typeshed/blob/fe6d09c5c1ff5dbd0116f53d07da239c8df99d66/stubs/WTForms/%40tests/test_cases/check_validators.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/typeshed/pull/10557/{{ revealButtonHref }}
stubs/WTForms/@tests/test_cases/check_widgets.pyhttps://github.com/python/typeshed/pull/10557/files#diff-20faf28c751f575d96757288824ad3868007ba7dcab3da5734295c22202089ad
View file https://github.com/Daverball/typeshed/blob/fe6d09c5c1ff5dbd0116f53d07da239c8df99d66/stubs/WTForms/%40tests/test_cases/check_widgets.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/typeshed/pull/10557/{{ revealButtonHref }}
stubs/WTForms/METADATA.tomlhttps://github.com/python/typeshed/pull/10557/files#diff-4200a254b91c661c43bf068713e47910d77f47faf19be2be40a906b095a87c7a
View file https://github.com/Daverball/typeshed/blob/fe6d09c5c1ff5dbd0116f53d07da239c8df99d66/stubs/WTForms/METADATA.toml
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/typeshed/pull/10557/{{ revealButtonHref }}
stubs/WTForms/wtforms/__init__.pyihttps://github.com/python/typeshed/pull/10557/files#diff-def7eab834b37707e59a9897bc438eea4c45051c7d9c9f8e8d6d81e4989935d5
View file https://github.com/Daverball/typeshed/blob/fe6d09c5c1ff5dbd0116f53d07da239c8df99d66/stubs/WTForms/wtforms/__init__.pyi
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/typeshed/pull/10557/{{ revealButtonHref }}
stubs/WTForms/wtforms/csrf/__init__.pyihttps://github.com/python/typeshed/pull/10557/files#diff-46d036e7aa9163aa36420938a7b8012ddc70f0faf7e13d9cc34ba3b7a11933bd
View file https://github.com/Daverball/typeshed/blob/fe6d09c5c1ff5dbd0116f53d07da239c8df99d66/stubs/WTForms/wtforms/csrf/__init__.pyi
Open in desktop https://desktop.github.com
stubs/WTForms/wtforms/csrf/core.pyihttps://github.com/python/typeshed/pull/10557/files#diff-2efdbc691c1ca536db4eedd7af3ad063fe8526c4eb10c16d0be9029a0726deda
View file https://github.com/Daverball/typeshed/blob/fe6d09c5c1ff5dbd0116f53d07da239c8df99d66/stubs/WTForms/wtforms/csrf/core.pyi
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/typeshed/pull/10557/{{ revealButtonHref }}
stubs/WTForms/wtforms/csrf/session.pyihttps://github.com/python/typeshed/pull/10557/files#diff-296af9240fe87fd8efe605a7cbde3964df03979b80190a70c029ef4daedc78ef
View file https://github.com/Daverball/typeshed/blob/fe6d09c5c1ff5dbd0116f53d07da239c8df99d66/stubs/WTForms/wtforms/csrf/session.pyi
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/typeshed/pull/10557/{{ revealButtonHref }}
stubs/WTForms/wtforms/fields/__init__.pyihttps://github.com/python/typeshed/pull/10557/files#diff-affaf192ccb4bd6a730b221783e451f5eb220174898db1dae64e2d3c6c6a91f3
View file https://github.com/Daverball/typeshed/blob/fe6d09c5c1ff5dbd0116f53d07da239c8df99d66/stubs/WTForms/wtforms/fields/__init__.pyi
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/typeshed/pull/10557/{{ revealButtonHref }}
stubs/WTForms/wtforms/fields/choices.pyihttps://github.com/python/typeshed/pull/10557/files#diff-0602f2cf15e64d6d3b73c20c28e285a414175c4809377d01643051ae5f178eea
View file https://github.com/Daverball/typeshed/blob/fe6d09c5c1ff5dbd0116f53d07da239c8df99d66/stubs/WTForms/wtforms/fields/choices.pyi
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/typeshed/pull/10557/{{ revealButtonHref }}
Please reload this pagehttps://github.com/python/typeshed/pull/10557/files
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.