René's URL Explorer Experiment


Title: revisiting decorators for actions/properties/etc. · Issue #237 · labthings/python-labthings · GitHub

Open Graph Title: revisiting decorators for actions/properties/etc. · Issue #237 · labthings/python-labthings

X Title: revisiting decorators for actions/properties/etc. · Issue #237 · labthings/python-labthings

Description: I am sure we have discussed in the past the merits of defining a View subclass for each endpoint, e.g. in an Extension. I have a nasty feeling that I probably argued strongly against using decorators because they often make life quite co...

Open Graph Description: I am sure we have discussed in the past the merits of defining a View subclass for each endpoint, e.g. in an Extension. I have a nasty feeling that I probably argued strongly against using decorato...

X Description: I am sure we have discussed in the past the merits of defining a View subclass for each endpoint, e.g. in an Extension. I have a nasty feeling that I probably argued strongly against using decorato...

Opengraph URL: https://github.com/labthings/python-labthings/issues/237

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"revisiting decorators for actions/properties/etc.","articleBody":"I am sure we have discussed in the past the merits of defining a `View` subclass for each endpoint, e.g. in an `Extension`.  I have a nasty feeling that I probably argued strongly against using decorators because they often make life quite confusing.  However, I'm coming round to the idea.  My use case is this:\r\n\r\nI'm writing some code in an extension, which includes a function to do something.  For argument's sake let's say that function should be an `Action` but I think the same consideration applies to properties.  Ideally, I'd like it to be accessible either via HTTP or via Python.  Currently, what I do is:\r\n\r\n1. Write the Python function that does what I want (and give it a helpful docstring) as a method of my Extension\r\n2. Define another class wrapping that Python function in a way that can be called nicely from the API\r\n3. Reference said class from within the Extension class so it appears in the AP\r\n\r\nThere are several things that are less than ideal here:\r\n\r\n1. You end up defining your arguments in multiple places - specifically, in both the method and the View class.\r\n2. Docstrings don't propagate from the method to the View, so the HTTP API docs are not great\r\n\r\nI can see a few ways to make it better: \r\n1. Be more explicit about the fact that `ActionView` classes are more or less always wrapping a function to do an action.  This would, for example, mean that instead of writing a `post` method, I would supply an `action` function.  Doing that explicitly makes it way easier to wrap the action function nicely, e.g. propagate the docstrings.\r\n2. Provide a decorator to put the definition of the `ActionView` right next to the function it's wrapping.  This makes it harder to miss things being out of sync, and could also eliminate the need to register views explicitly.\r\n\r\nI think if I argued against custom decorators in the past, it was because I felt they were non-standard ways of doing things, and wouldn't make sense to someone familiar with Flask.  That's true, but I think there's enough that's non-standard about e.g. the way we generate our APISpec that this battle is possibly lost anyway.  Also, if we define a more \"helpful\" `ActionView` subclass, it potentially provides a point of familiarity for Flask developers - so if they understand how `@action` maps onto `ActionViewWrapper` (which is potentially quite simple), it's easier to figure out what happens once you have a `View`.\r\n\r\nAlso, I think when we made this decision, it was more likely that you would want control over the get/post/delete/whatever methods.  Now that the WoT specification is finalised, it's pretty well defined what each HTTP method should do, and I'm in favour of providing a mapping from HTTP methods to meaningful WoT interactions.  I.e. a `PropertyView` always reads a property with `GET` and writes it with `PUT` and may define a way to update it with `POST`.  So probably we should, by default, define a getter, setter, and update method - not all of which must exist.  Similarly, an `ActionView` will always run actions with `POST` and return status with `GET`, so it makes sense to simply have a function responsible for running the action (which is what's currently implemented in `ActionView.post`.  This also means that overriding `ActionView.post` would allow an action to do something custom *before* it's spawned in a background thread, such as validating arguments and returning an HTTP error code if they're wrong.\r\n\r\nI'm raising this issue so @jtc42 can tell me why I was dead against this in the past, or if he remembers anything important that's not reflected in the discussion above.","author":{"url":"https://github.com/rwb27","@type":"Person","name":"rwb27"},"datePublished":"2021-06-30T09:32:41.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/237/python-labthings/issues/237"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:34807620-fafb-cb1d-d734-9429e74fa3ab
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE6D2:9763B:9893C5:C54375:698FD4F1
html-safe-nonce7bef7a6da1ecf8896d73ca8f4a79ecd8f05d65e8e3f56b1913308520dfac3ba3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNkQyOjk3NjNCOjk4OTNDNTpDNTQzNzU6Njk4RkQ0RjEiLCJ2aXNpdG9yX2lkIjoiNjgxNzU4MzAwMTU0MDQ4MjI4OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac5d1a6a2ff68704c02fee412ddd3d1e318a63a062f82d6453eabf8bfcabfad9b4
hovercard-subject-tagissue:933494361
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/labthings/python-labthings/237/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b68fedd7e18504a8ff322ccd35cefdcc22f9734036f4d491cd88f9de7323d8d5/labthings/python-labthings/issues/237
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b68fedd7e18504a8ff322ccd35cefdcc22f9734036f4d491cd88f9de7323d8d5/labthings/python-labthings/issues/237
og:image:altI am sure we have discussed in the past the merits of defining a View subclass for each endpoint, e.g. in an Extension. I have a nasty feeling that I probably argued strongly against using decorato...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerwb27
hostnamegithub.com
expected-hostnamegithub.com
None42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b
turbo-cache-controlno-preview
go-importgithub.com/labthings/python-labthings git https://github.com/labthings/python-labthings.git
octolytics-dimension-user_id58913024
octolytics-dimension-user_loginlabthings
octolytics-dimension-repository_id234552142
octolytics-dimension-repository_nwolabthings/python-labthings
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id234552142
octolytics-dimension-repository_network_root_nwolabthings/python-labthings
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
released320682233dfd4d28c0b30554a564c2fcd229032
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/labthings/python-labthings/issues/237#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Flabthings%2Fpython-labthings%2Fissues%2F237
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Flabthings%2Fpython-labthings%2Fissues%2F237
Sign up https://patch-diff.githubusercontent.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=labthings%2Fpython-labthings
Reloadhttps://patch-diff.githubusercontent.com/labthings/python-labthings/issues/237
Reloadhttps://patch-diff.githubusercontent.com/labthings/python-labthings/issues/237
Reloadhttps://patch-diff.githubusercontent.com/labthings/python-labthings/issues/237
labthings https://patch-diff.githubusercontent.com/labthings
python-labthingshttps://patch-diff.githubusercontent.com/labthings/python-labthings
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Flabthings%2Fpython-labthings
Fork 2 https://patch-diff.githubusercontent.com/login?return_to=%2Flabthings%2Fpython-labthings
Star 19 https://patch-diff.githubusercontent.com/login?return_to=%2Flabthings%2Fpython-labthings
Code https://patch-diff.githubusercontent.com/labthings/python-labthings
Issues 14 https://patch-diff.githubusercontent.com/labthings/python-labthings/issues
Pull requests 10 https://patch-diff.githubusercontent.com/labthings/python-labthings/pulls
Actions https://patch-diff.githubusercontent.com/labthings/python-labthings/actions
Projects 0 https://patch-diff.githubusercontent.com/labthings/python-labthings/projects
Security 0 https://patch-diff.githubusercontent.com/labthings/python-labthings/security
Insights https://patch-diff.githubusercontent.com/labthings/python-labthings/pulse
Code https://patch-diff.githubusercontent.com/labthings/python-labthings
Issues https://patch-diff.githubusercontent.com/labthings/python-labthings/issues
Pull requests https://patch-diff.githubusercontent.com/labthings/python-labthings/pulls
Actions https://patch-diff.githubusercontent.com/labthings/python-labthings/actions
Projects https://patch-diff.githubusercontent.com/labthings/python-labthings/projects
Security https://patch-diff.githubusercontent.com/labthings/python-labthings/security
Insights https://patch-diff.githubusercontent.com/labthings/python-labthings/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/labthings/python-labthings/issues/237
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/labthings/python-labthings/issues/237
revisiting decorators for actions/properties/etc.https://patch-diff.githubusercontent.com/labthings/python-labthings/issues/237#top
https://github.com/rwb27
https://github.com/rwb27
rwb27https://github.com/rwb27
on Jun 30, 2021https://github.com/labthings/python-labthings/issues/237#issue-933494361
@jtc42https://github.com/jtc42
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.