GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Allow parsing source code directly by bzoracler · Pull Request #54 · mypyc/ast_serialize Conversation
|
|
Thanks for the PR! Me or Jukka will try to take a look next week. In the meantime, could you please resolve the merge conflict? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| match pyo3::exceptions::PyUnicodeDecodeError::new_utf8( | ||
| obj.py(), | ||
| e.as_bytes(), | ||
| utf8_err, | ||
| ) { | ||
| Ok(err) => Self::Error::from_value(err.into_any()), | ||
| Err(err) => err, | ||
| } |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Implementation taken from https://pyo3.rs/main/doc/src/pyo3/exceptions.rs#802-811 (PR https://github.com/PyO3/pyo3/pull/5668/changes), because new_err_from_utf8 is only in pyo3 0.29 which is not released yet.
The test is here: python/mypy@ac275e4
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| )> { | ||
| serialize_module( | ||
| source, | ||
| PySourceType::Python, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've hard-coded Python source type here, because mypy parsing functions never previously exposed an option to let the user treat source code directly as a .pyi stub source.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to use the same logic as for serialize_module().
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hmm...there might be some unnecessary allocations that are preventable. I'm going to do some benchmarking with another implementation. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
If we're willing to use Performance of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, but will wait for Ivan or Jukka.
Mypy has dropped support for Python 3.9, so I would also take a PR dropping 3.9 support and increasing the stable ABI
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good, but I have couple comments about respecting the file name when parsing source. It is better be consistent in case mypy (or other user) will decide to open/read file manually for some reason and pass the source. They should get identical result as when passing the file name.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| PySourceType::Python, | ||
| skip_function_bodies, | ||
| options, | ||
| false, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This should not be false, we should always respect the file name provided.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| )> { | ||
| serialize_module( | ||
| source, | ||
| PySourceType::Python, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to use the same logic as for serialize_module().
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@ilevkivskyi Whoops, I thought providing source contents was only used via |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
OK, this looks good as a good starting point. I think we will need some more things to make native parser a full replacement, but it is probably better to move in small increments. I will merge this now, release a new version, then we can continue discussion in the mypy PR.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
This is the mypy counterpart of mypyc/ast_serialize#54 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ivan Levkivskyi <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Support parsing strings in addition to files
There was an error while loading. Please reload this page.