-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Stability fixup: address stability issues relating to interaction between magic commas and invisible parentheses #1958
Stability fixup: address stability issues relating to interaction between magic commas and invisible parentheses #1958
Conversation
…rrently always returns False for non-atom nodes, making the 'wrap_in_parentheses' call unreachable
@ambv Apologies to ping directly, you might receive a lot of notifications. I think there's something of interest to you here though. It's almost possible to make the This would allow simplifying the There's a catch somewhere, though. It has to do with some of the |
I was very excited when I saw the PR title; I think this change may also fix many of the issues mentioned in #1629. |
It seems similar, in that it does relate to the introduction/removal of invisible parentheses. In the example I've been looking at locally for this branch, the calls to One question is whether invisible parens should have been introduced at all (they do seem valid for return and assert statements though, I think?); another is whether they could have been valid for omission. Is is the latter case where the introduction of a trailing comma to the function argument list ( |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
NB: Although the |
…nuous integration
These are generally cases where example code was provided by a user and it was straightforward to copy and confirm the stability test failure for that code
This reverts commit 6c6d262.
…by continuous integration" This reverts commit 543fc7e.
This reverts commit 23facce.
…t case" This reverts commit d262d29.
… and return statements" This reverts commit f154042.
This reverts commit 82ab09d.
…atom' currently always returns False for non-atom nodes, making the 'wrap_in_parentheses' call unreachable" This reverts commit 0bb718c.
…e it has stabilized" This reverts commit fdff084.
Black logMode(target_versions=set(), line_length=88, string_normalization=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -112,14 +112,14 @@
):
# FIXME: This doesn't really work - PySide2 doesn't have QWebEngineNotification
self.browser.page().setFeaturePermission(
origin, feature, QWebEnginePage.PermissionGrantedByUser
)
- elif (
- feature in (QWebEnginePage.DesktopVideoCapture, QWebEnginePage.DesktopAudioVideoCapture)
- and self.app.has_permission('pixel')
- ):
+ elif feature in (
+ QWebEnginePage.DesktopVideoCapture,
+ QWebEnginePage.DesktopAudioVideoCapture,
+ ) and self.app.has_permission("pixel"):
self.browser.page().setFeaturePermission(
origin, feature, QWebEnginePage.PermissionGrantedByUser
)
else:
self.browser.page().setFeaturePermission(
--- first pass
+++ second pass
@@ -112,14 +112,18 @@
):
# FIXME: This doesn't really work - PySide2 doesn't have QWebEngineNotification
self.browser.page().setFeaturePermission(
origin, feature, QWebEnginePage.PermissionGrantedByUser
)
- elif feature in (
- QWebEnginePage.DesktopVideoCapture,
- QWebEnginePage.DesktopAudioVideoCapture,
- ) and self.app.has_permission("pixel"):
+ elif (
+ feature
+ in (
+ QWebEnginePage.DesktopVideoCapture,
+ QWebEnginePage.DesktopAudioVideoCapture,
+ )
+ and self.app.has_permission("pixel")
+ ):
self.browser.page().setFeaturePermission(
origin, feature, QWebEnginePage.PermissionGrantedByUser
)
else:
self.browser.page().setFeaturePermission( |
Oh sorry, nevermind, I got lost in the black installation virtualenvs. That file works too |
No worries, thank you again - both successful confirmations, and remaining failure cases are good to know about. I do have a remaining concern that although the changes appear to work in most cases, they also allow exceeding the line-length in some situations, and that might or might not be acceptable to the project team. We'll see. |
Ok, this time I really got something: def f():
def f():
def f():
optr = self._hptr + {ps.icmp6.ROUTER_SOLICITATION: 12, ps.icmp6.ROUTER_ADVERTISEMENT: 16, ps.icmp6.NEIGHBOR_SOLICITATION: 24, ps.icmp6.NEIGHBOR_ADVERTISEMENT: 24}[self.type] Black log, identical on master and this patchMode(target_versions=set(), line_length=88, string_normalization=True, magic_trailing_comma=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -1,4 +1,12 @@
def f():
def f():
def f():
- optr = self._hptr + {ps.icmp6.ROUTER_SOLICITATION: 12, ps.icmp6.ROUTER_ADVERTISEMENT: 16, ps.icmp6.NEIGHBOR_SOLICITATION: 24, ps.icmp6.NEIGHBOR_ADVERTISEMENT: 24}[self.type]
+ optr = (
+ self._hptr
+ + {
+ ps.icmp6.ROUTER_SOLICITATION: 12,
+ ps.icmp6.ROUTER_ADVERTISEMENT: 16,
+ ps.icmp6.NEIGHBOR_SOLICITATION: 24,
+ ps.icmp6.NEIGHBOR_ADVERTISEMENT: 24,
+ }[self.type]
+ )
--- first pass
+++ second pass
@@ -1,12 +1,9 @@
def f():
def f():
def f():
- optr = (
- self._hptr
- + {
- ps.icmp6.ROUTER_SOLICITATION: 12,
- ps.icmp6.ROUTER_ADVERTISEMENT: 16,
- ps.icmp6.NEIGHBOR_SOLICITATION: 24,
- ps.icmp6.NEIGHBOR_ADVERTISEMENT: 24,
- }[self.type]
- )
+ optr = self._hptr + {
+ ps.icmp6.ROUTER_SOLICITATION: 12,
+ ps.icmp6.ROUTER_ADVERTISEMENT: 16,
+ ps.icmp6.NEIGHBOR_SOLICITATION: 24,
+ ps.icmp6.NEIGHBOR_ADVERTISEMENT: 24,
+ }[self.type] From #1900 |
Good find, thanks @mvolfik. I'll look into that case soon. |
@mvolfik Just a note to let you know that I've taken a brief look at the test case you found - it's definitely valid, and I think it's possible that it exposes some kind of serious/core problem with this branch as it stands. I've experimented with a few adjustments to try to handle it, but overall I still don't yet fully understand the root problem in the parentheses/magic comma interaction, and I think that will be required for a complete fix. |
Other time commitments may mean that I won't be committing much additional code here (or be able to re-investigate the details) within the next few weeks. I'll do my best to respond to any feedback, suggestions and ideas; and if anyone's eager to, please feel free to take any of the code from this branch and develop / fix it further. |
@jayaddison, thanks for the tremendous amount of work you did on this PR. It only goes to show that the optional parentheses + optional trailing commas + magic trailing commas are a killer combination and it's impractical to solve the instability entirely, at least without introducing disruptive formatting changes in the process. I decided to go with #2126 a simpler, if less elegant, approach to this problem. |
Glad to have helped, @ambv; it was a good learning exercise - I think my favourite finding as a result was discovering the term I would definitely concur that something that becomes this puzzling is a difficult combination; if there's a way to update the codebase to simplify some of that in future -- potentially by reverting and backtracking on a few features like the ones you mention -- perhaps that'd help improve long-term maintainability. |
This changeset addresses some stability issues encountered during multi-pass code formatting by
black
.In particular, the changeset modifies handling of magic trailing commas within code lines. The most significant change is that the
generate_trailers_to_omit
method will delay or suppress yielding of an empty trailer (leaf set) when a magic comma is present in the line.May resolve #1629.
NB: Other time commitments may mean that I won't be committing much additional code here (or be able to re-investigate the details) within the next few weeks. I'll do my best to respond to any feedback, suggestions and ideas; and if anyone's eager to, please feel free to take any of the code from this branch and develop / fix it further.
Edit 20210312: added note from #1958 (comment)