Title: 0.5.0 a couple issues on first attempt to use · Issue #78 · python-trio/unasync · GitHub
Open Graph Title: 0.5.0 a couple issues on first attempt to use · Issue #78 · python-trio/unasync
X Title: 0.5.0 a couple issues on first attempt to use · Issue #78 · python-trio/unasync
Description: The async transformation code. Contribute to python-trio/unasync development by creating an account on GitHub.
Open Graph Description: The async transformation code. Contribute to python-trio/unasync development by creating an account on GitHub.
X Description: The async transformation code. Contribute to python-trio/unasync development by creating an account on GitHub.
Opengraph URL: https://github.com/python-trio/unasync
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"0.5.0 a couple issues on first attempt to use","articleBody":"1) trying to use this on Windows is producing bad EOL in output file. This is because the file is opened binary on read and pulls in '\\r\\n' but then the file is opened as text on output so ends up writing '\\r\\r\\n' to the output file\r\n\r\n2) need to support older versions of python but the following code:\r\n`from typing_extensions import AsyncIterator`\r\ngets transformed to the invalid:\r\n`from typing_extensions import Iterator`\r\n\r\n3) unasync output files are invalid if they use tabbed indentation. Source tabs are getting replaced with a single space on some but not all lines. Actual error trying to run a converted file:\r\n\r\n```\r\n File \"C:\\cvs\\gravitas_v1\\incpy\\esl_sync.py\", line 48\r\n if value is None:\r\n ^\r\nIndentationError: unindent does not match any outer indentation level\r\n```\r\n\r\n4) a simple way to run this by hand (setup.py is overkill for my needs) to convert a file to another file in the same directory. In my case I want to convert 'esl_async.py' to 'esl_sync.py' in the same folder. This is what I did in order to get this far:\r\n\r\n```\r\n# stdlib imports:\r\nimport os\r\nfrom pathlib import Path\r\nimport sys\r\n\r\n# 3rd-party imports:\r\nimport unasync # pip install unasync\r\nfrom unasync import std_tokenize, _tokenize, _makedirs_existok\r\n\r\ndef _untokenize(tokens):\r\n\treturn \"\".join(\r\n\t\tspace + '\\n' if tokval == '\\r\\n' else space + tokval\r\n\t\tfor space, tokval in tokens\r\n\t)\r\n\r\nclass Rule( unasync.Rule ):\r\n\tdef __init__( self, fromdir, todir, suffix ) -> None:\r\n\t\tself.suffix = suffix\r\n\t\tsuper().__init__( fromdir, todir )\r\n\t\r\n\tdef _outfilepath( self, filepath ):\r\n\t\tpath = Path( self.todir ).absolute() / f'{Path(filepath).stem}{self.suffix}.py'\r\n\t\t#assert False, f'{filepath=} {path=} {os.path.dirname(str(path))=}'\r\n\t\treturn str( path )\r\n\t\r\n\tdef _unasync_file( self, filepath ):\r\n\t\twith open(filepath, \"rb\") as f:\r\n\t\t\twrite_kwargs = {}\r\n\t\t\tif sys.version_info[0] >= 3:\r\n\t\t\t\tencoding, _ = std_tokenize.detect_encoding(f.readline)\r\n\t\t\t\twrite_kwargs[\"encoding\"] = encoding\r\n\t\t\t\tf.seek(0)\r\n\t\t\ttokens = _tokenize(f)\r\n\t\t\ttokens = self._unasync_tokens(tokens)\r\n\t\t\tresult = _untokenize(tokens)\r\n\t\t\toutfilepath = self._outfilepath( filepath )\r\n\t\t\t_makedirs_existok(os.path.dirname(outfilepath))\r\n\t\t\twith open(outfilepath, \"w\", **write_kwargs) as f:\r\n\t\t\t\tprint(result, file=f, end=\"\")\r\n\r\nrule = Rule( '.', '.', '_sync' )\r\nrule._unasync_file( 'esl.py' )\r\n```\r\n","author":{"url":"https://github.com/remdragon","@type":"Person","name":"remdragon"},"datePublished":"2022-12-17T00:42:51Z","url":"https://github.com/python-trio/unasync/issues/78"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:1c56fd9f-16ef-9a68-3d20-8b77dd6b63e4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B3B2:81334:311D16:44AE96:6B047700 |
| html-safe-nonce | bcdbb972ab0caa6d1e4549a53b372cf13bd89bb149fe5aeb65d64a40779843ec |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0IyOjgxMzM0OjMxMUQxNjo0NEFFOTY6NkIwNDc3MDAiLCJ2aXNpdG9yX2lkIjoiNTc5MDAwNzgwMjUwNDQ0MzY0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 66effbe1d2421be4078aef52c6880978064be2e41f7a017b4ed3b865fe11f3d1 |
| hovercard-subject-tag | repository:154537846 |
| 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/python-trio/unasync/issues/78 |
| twitter:image | https://opengraph.githubassets.com/8570c3e566624e0755e1d3c811d13a6c449736589f13d3f372157de3a04c18b9/python-trio/unasync |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8570c3e566624e0755e1d3c811d13a6c449736589f13d3f372157de3a04c18b9/python-trio/unasync |
| og:image:alt | The async transformation code. Contribute to python-trio/unasync development by creating an account on GitHub. |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9c099f1b85def81ca352464c276510dfef32deaf3c305404e65b8d270284a58b |
| turbo-cache-control | no-cache |
| go-import | github.com/python-trio/unasync git https://github.com/python-trio/unasync.git |
| octolytics-dimension-user_id | 26335827 |
| octolytics-dimension-user_login | python-trio |
| octolytics-dimension-repository_id | 154537846 |
| octolytics-dimension-repository_nwo | python-trio/unasync |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 154537846 |
| octolytics-dimension-repository_network_root_nwo | python-trio/unasync |
| 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 | cf73f57448d52b3a7b619195e182b33d3b3454ca |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width