-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
option to merge stubs into source trees #5139
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a couple of stylistic comments.
I think this would need a flag to enable it; I expect that not everybody will want this functionality. This PR probably ought to be merged quickly to avoid running into merge conflicts; but it requires very thorough review (probably by Jukka or Ivan). |
@gvanrossum fair enough, I'll hide it behind a flag. |
I can review this later this week. Agreed that we want to merge this quickly -- even if this is not 100% finished, if it's behind a flag and doesn't risk breaking other functionality we can hopefully merge it, and it can be iterated on afterwards. |
Running works fine. Debugging though generates this extra attached output
which breaks the tests. Probably should reformulate to debugging instead
running.
…On Thu, Jun 7, 2018, 19:47 Ethan Smith ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In mypy/test/testcmdline.py
<#5139 (comment)>:
> @@ -58,6 +58,14 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None:
outb = process.stdout.read()
# Split output into lines.
out = [s.rstrip('\n\r') for s in str(outb, 'utf8').splitlines()]
+
+ is_running_in_py_charm = "PYCHARM_HOSTED" in os.environ
How are you running things from PyCharm? I've been able to run the test
suite for months without issue.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#5139 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAqIPkEtNylTSnLOQsaib9nJuPltkn7qks5t6XUmgaJpZM4UYCqM>
.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a quick overview review pass. The general approach looks reasonable. Thanks for working on this -- this has been requested several times.
I suspect that there are various remaining edge cases, some of which may be a bit tricky (conditional definitions, for example). This just means that this feature needs some real-world use and iteration before it will be generally useful, most of which can happen in separate PRs.
Here's my suggestion for the next steps:
- Get tests to pass and do some minimal clean-up such as separating unrelated changes from this PR.
- A core team member (probably me) will try this out and do a more detailed review. The review can be pretty lenient since this is a big feature and we can't expect this to be finished in a single PR.
- Merge this PR. At this point the feature may be undocumented/hidden, depending on how mature we feel this is.
- Create follow-up issues for additional work. [Are you willing to continue working on this after a basic implementation gets merged, by the way? If yes, it's easier to justify merging an incomplete feature.]
- After some iteration make this public as an experimental feature and invite other mypy users to try this out and send feedback.
Finally, the PR doesn't quite follow the style used elsewhere in the codebase. Are you okay with changing the style? At least some of this can happen after this has been merged.
Hello @JukkaL,
As far as style goes whatever you guys want. For all new files I've used the excellent fully automated black formatter with isort import ordering mostly because I prefer spending my mental power on the implementation difficulties rather than how to indent/space my code. That being said I'm not married or attached to any style on my side. Ideally we would have this change automated but if not possible I can alter manually here and there. |
A suggestion: if changes unrelated to this topic would benefit others
developing mypy, why not submit then as separate PRs? Once accepted you can
merge and they won't be part of this PR yet. (Of course these need to be
things that don't get in the way of using mypy or other development
workflows -- checking for environment variables might be useful here.)
|
@gvanrossum that would be great and I plan to do that. I don't completely understand what's the current development workflow used by core devs, so my changes don't get in way. Those can be probably discussed inside that pr though. |
Mostly we don't use PyCharm much. :-)
|
#5189 now contains the changes unrelated to this PR. |
So this is now in a review ready state I would say (all tests now pass). Before v0.1 I think I just need to add proper cache handling, some documentation on it. And we're good to go I would say. However, the underlying merge logic is now the proposed one so ready for review. |
I can't get this to work on the command line. I created a stub file
Similarly, if I add a syntax error to
|
@JukkaL it does not work like that; only support now specifying the directory. The source finder logic does the collection of files, and then matching stub files with source files; and that's only used if you do That being said I believe, the way could work:
|
Thanks for the hint, now I got this to merge some files.
These all look reasonable. In addition, if I don't include a module explicitly on the command line and the module is found by following imports, we should perform a merge (this corresponds to the I've found a couple of additional issues. First, if I define function Second, the type of an imported name from a merged module is wrong, and it can cause crashes. Here is an example:
If I type check the above example I get a crash:
The likely reason for the crash is on the first line of output ( |
Will try to tackle the raised issues. |
mypy/stub_src_merge.py
Outdated
) | ||
) | ||
elif report: # pragma: no cover | ||
# TODO: how can we have more than one l-value in an assignment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x = y = 1
Btw, what is the status of this PR? We will have a release next week, is this ready for a review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I'll have enough time to get it into a proper state, as I'm caught up with some tox
maintenance. Will probably pick it up next week again, so let's aim for the next release cycle. Would not like to rush things and mess something somewhere up.
This seems stalled...? |
Actually I'm just planning to pick it up again. @JukkaL change requests are non trivial so this got put back on my schedule a bit. |
OK, both Jukka and I are on vacation, so be patient... (I tried to send this before but somehow the mail bounced.) |
No worries I still need to work a bit on this before review/merge time. By the way how do we handle the lack of Type on Python 3.5 and less. Needed to type hint the code of this PR. |
@gaborbernat you can do:
And then string escape |
@JukkaL picking this up again, so what blockers we need to get this merged? 👍 |
Based on a quick review pass, these may be sufficient to get this merged:
It would also be good to have some commitment for additional work, since this is a pretty big feature. As discussed above, there will likely be various features and edge cases that would still need more work after this PR. |
mypy/find_sources.py
Outdated
allow_empty_dir: bool = False) -> List[BuildSource]: | ||
def partition( | ||
pred: Callable[[str], bool], iterable: Iterable[str] | ||
) -> Tuple[Iterable[str], Iterable[str]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use this style for multi-line signatures. The original signature conforms to our style.
mypy/find_sources.py
Outdated
options: Options, | ||
fscache: Optional[FileSystemCache] = None, | ||
allow_empty_dir: bool = False, | ||
) -> List[BuildSource]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another signature with inconsistent style.
mypy/test/test_source_finder.py
Outdated
return _checker | ||
|
||
|
||
def test_source_finder_merge(merge_finder: MergeFinder) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put these tests inside a test class derived from unittest.TestCase
, for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, will do 👍
Sorry, I've been busy with other things to finish the review. If you are still interested in finishing this up, I can dedicate some time to reviewing this in May. (Or maybe during PyCon sprints, in case you are coming there.) |
@JukkaL yeah I still plan to finish it, will try to make it in some merge-able state by the sprint is my current plan (and yes I'll be there 😄 - I actually have a talk accepted about mypy 🤔 ) |
Resolves #5028.
Need to clean up, both logic mostly there (tested with https://github.com/gaborbernat/tox/tree/type-hint-stubs/tox).