Title: functools.wraps does not work on class methods · Issue #10653 · python/typeshed · GitHub
Open Graph Title: functools.wraps does not work on class methods · Issue #10653 · python/typeshed
X Title: functools.wraps does not work on class methods · Issue #10653 · python/typeshed
Description: We recently hit an error using @wraps on a class method in Trio: python-trio/trio#2775 (comment) when checked with pyright. It works fine on mypy, but I'm guessing they might be special-casing wraps usage while pyright doesn't. Minimal r...
Open Graph Description: We recently hit an error using @wraps on a class method in Trio: python-trio/trio#2775 (comment) when checked with pyright. It works fine on mypy, but I'm guessing they might be special-casing wrap...
X Description: We recently hit an error using @wraps on a class method in Trio: python-trio/trio#2775 (comment) when checked with pyright. It works fine on mypy, but I'm guessing they might be special-casing ...
Opengraph URL: https://github.com/python/typeshed/issues/10653
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"functools.wraps does not work on class methods","articleBody":"We recently hit an error using `@wraps` on a class method in Trio: https://github.com/python-trio/trio/issues/2775#issuecomment-1702892474 when checked with pyright. It works fine on mypy, but I'm guessing they might be special-casing wraps usage while pyright doesn't.\r\n\r\nMinimal repro (python 3.11):\r\n```python\r\nfrom functools import wraps\r\nfrom typing import assert_type\r\n\r\n\r\ndef foo(param: int) -> str:\r\n \"\"\"docstring\"\"\"\r\n return \"\"\r\n\r\n@wraps(foo)\r\ndef my_function(blah: int) -> str:\r\n return 'foo'\r\n\r\n# works fine\r\nassert_type(my_function(5), str)\r\n\r\nclass MyOtherClass:\r\n def bar(self, param: int) -> str:\r\n \"\"\"docstring\"\"\"\r\n return \"\"\r\n\r\nclass MyClass:\r\n @wraps(MyOtherClass.bar)\r\n def my_method(self, blah: int) -> str:\r\n return 'foo'\r\n\r\ninstance = MyClass()\r\n# works in mypy, but not pyright\r\nassert_type(instance.my_method(5), str)\r\n```\r\n\r\nmypy 1.5.1 works without any issue, pyright 1.1.325 gives\r\n```\r\n./test.py\r\n ./test.py:26:13 - error: Argument missing for parameter \"blah\" (reportGeneralTypeIssues)\r\n ./test.py:26:13 - error: \"assert_type\" mismatch: expected \"str\" but received \"Unknown\" (reportGeneralTypeIssues)\r\n2 errors, 0 warnings, 0 informations \r\n```\r\n\r\nThis smells a lot like the problem with getting functools.cache to work both with methods and functions, see e.g. https://github.com/python/typeshed/issues/6347","author":{"url":"https://github.com/jakkdl","@type":"Person","name":"jakkdl"},"datePublished":"2023-09-02T10:10:21Z","url":"https://github.com/python/typeshed/issues/10653"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:73184735-83b3-87c2-9c45-64103475efa0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B2A4:30263F:1BACDAA:25658EE:6B0005E5 |
| html-safe-nonce | 64ad56a4f675538be12accaaecf544d67da9a559caf2c54bc3abdcff2a26b00d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMkE0OjMwMjYzRjoxQkFDREFBOjI1NjU4RUU6NkIwMDA1RTUiLCJ2aXNpdG9yX2lkIjoiNTU1Mjc2OTkyMzc5MDQwNzE0MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5e7a60310f0dd0a3499259032390ca6a275502d771a19c8ad8abbdefc281f7e2 |
| hovercard-subject-tag | issue:1878568188 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/typeshed/10653/issue_layout |
| twitter:image | https://opengraph.githubassets.com/28ff1602f8c44bae9b259741b76ab90021b92b5d2110b696a53402440e0ed304/python/typeshed/issues/10653 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/28ff1602f8c44bae9b259741b76ab90021b92b5d2110b696a53402440e0ed304/python/typeshed/issues/10653 |
| og:image:alt | We recently hit an error using @wraps on a class method in Trio: python-trio/trio#2775 (comment) when checked with pyright. It works fine on mypy, but I'm guessing they might be special-casing wrap... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jakkdl |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width