Title: Mypyc should support `__file__` · Issue #17795 · python/mypy · GitHub
Open Graph Title: Mypyc should support `__file__` · Issue #17795 · python/mypy
X Title: Mypyc should support `__file__` · Issue #17795 · python/mypy
Description: Feature Mypyc should set __file__ Pitch Getting installation directory is important when referencing data files included in your package. Things like this are common: DATA_FOLDER: Final = Path(__file__).parent / "data" Currently, mypyc w...
Open Graph Description: Feature Mypyc should set __file__ Pitch Getting installation directory is important when referencing data files included in your package. Things like this are common: DATA_FOLDER: Final = Path(__fi...
X Description: Feature Mypyc should set __file__ Pitch Getting installation directory is important when referencing data files included in your package. Things like this are common: DATA_FOLDER: Final = Path(__fi...
Opengraph URL: https://github.com/python/mypy/issues/17795
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mypyc should support `__file__`","articleBody":"**Feature**\r\n\r\nMypyc should set `__file__`\r\n\r\n**Pitch**\r\n\r\nGetting installation directory is important when referencing data files included in your package.\r\nThings like this are common:\r\n```python\r\nDATA_FOLDER: Final = Path(__file__).parent / \"data\"\r\n```\r\nCurrently, mypyc will compile this with no warnings about possible issues and crash with\r\n```\r\nTraceback (most recent call last):\r\n \u003cunrelated details>\r\n File \"src/checkers/game.py\", line 108, in \u003cmodule>\r\n DATA_FOLDER: Final = Path(__file__).parent / \"data\"\r\nKeyError: '__file__'\r\n```\r\n\r\nThere is a workaround for this, doing something like this before hand\r\n```python\r\nif globals().get(\"__file__\") is None:\r\n import inspect\r\n __file__ = inspect.stack()[0].filename\r\n```\r\nbut that's messy","author":{"url":"https://github.com/CoolCat467","@type":"Person","name":"CoolCat467"},"datePublished":"2024-09-20T04:56:23Z","url":"https://github.com/python/mypy/issues/17795"}
| 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:d678018f-bf9c-a280-8756-e0303e3e6621 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B000:1AC37C:5018AF:6B4DCC:6B003011 |
| html-safe-nonce | 919448352e1272d4bf1b6e86e3c6c1a20945aaaa7dcf42f5144ba414cbaba3b3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDAwOjFBQzM3Qzo1MDE4QUY6NkI0RENDOjZCMDAzMDExIiwidmlzaXRvcl9pZCI6Ijg2NjI4NTAwMzQ1MzYwMzQzMjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4c04f331b4bcdfb60bf82642114eb9c14793da5e29195c8682af0b8613454d34 |
| hovercard-subject-tag | issue:2537874404 |
| 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/mypy/17795/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5dc8119f06f0fc8c36d64d3cad0248554061f6997a057c11719fc6122b112e12/python/mypy/issues/17795 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5dc8119f06f0fc8c36d64d3cad0248554061f6997a057c11719fc6122b112e12/python/mypy/issues/17795 |
| og:image:alt | Feature Mypyc should set __file__ Pitch Getting installation directory is important when referencing data files included in your package. Things like this are common: DATA_FOLDER: Final = Path(__fi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | CoolCat467 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width