You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/09/14 23:52:45 UTC

[GitHub] [beam] robertwb opened a new pull request, #23242: Fix type inference for set/delete attr.

robertwb opened a new pull request, #23242:
URL: https://github.com/apache/beam/pull/23242

   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] [**Choose reviewer(s)**](https://beam.apache.org/contribute/#make-your-change) and mention them in a comment (`R: @username`).
    - [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
    - [ ] Update `CHANGES.md` with noteworthy changes.
    - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://beam.apache.org/contribute/get-started-contributing/#make-the-reviewers-job-easier).
   
   To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
   
   GitHub Actions Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   [![Build python source distribution and wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Go tests](https://github.com/apache/beam/workflows/Go%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] github-actions[bot] commented on pull request #23242: Fix type inference for set/delete attr.

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #23242:
URL: https://github.com/apache/beam/pull/23242#issuecomment-1247412874

   Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] yeandy commented on pull request #23242: Fix type inference for set/delete attr.

Posted by GitBox <gi...@apache.org>.
yeandy commented on PR #23242:
URL: https://github.com/apache/beam/pull/23242#issuecomment-1263659015

   LGTM


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] robertwb commented on a diff in pull request #23242: Fix type inference for set/delete attr.

Posted by GitBox <gi...@apache.org>.
robertwb commented on code in PR #23242:
URL: https://github.com/apache/beam/pull/23242#discussion_r984103609


##########
sdks/python/apache_beam/typehints/trivial_inference_test.py:
##########
@@ -258,6 +258,26 @@ def testGetAttr(self):
         typehints.Tuple[str, typehints.Any],
         lambda: (typehints.__doc__, typehints.fake))
 
+  def testSetAttr(self):
+    def fn(obj, flag):
+      global glob
+      if flag == 1:
+        obj.attr = 1
+        res = 1
+      elif flag == 2:
+        obj.attr = 2
+        res = 1.5
+      elif flag == 3:
+        glob = 3
+        res = "str"
+      elif flag == 4:
+        del glob
+        res = "another str"
+      return res
+    self.assertReturnType(
+        typehints.Union[int, float, str],
+        fn, [int])

Review Comment:
   Done.



##########
sdks/python/apache_beam/typehints/trivial_inference_test.py:
##########
@@ -258,6 +258,26 @@ def testGetAttr(self):
         typehints.Tuple[str, typehints.Any],
         lambda: (typehints.__doc__, typehints.fake))
 
+  def testSetAttr(self):
+    def fn(obj, flag):
+      global glob

Review Comment:
   Yes, these were correct, but I added a test for them. I've now separated that out into a separate test to be more clear (and disabled the hint warning that isn't useful here).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] yeandy commented on a diff in pull request #23242: Fix type inference for set/delete attr.

Posted by GitBox <gi...@apache.org>.
yeandy commented on code in PR #23242:
URL: https://github.com/apache/beam/pull/23242#discussion_r971992233


##########
sdks/python/apache_beam/typehints/opcodes.py:
##########
@@ -241,8 +241,8 @@ def dup_topx(state, arg):
   state.stack += state[-arg:]
 
 
-store_attr = pop_top
-delete_attr = nop

Review Comment:
   Can you provide more context on this change? Where there any previous issues/failures?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] robertwb merged pull request #23242: Fix type inference for set/delete attr.

Posted by GitBox <gi...@apache.org>.
robertwb merged PR #23242:
URL: https://github.com/apache/beam/pull/23242


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] codecov[bot] commented on pull request #23242: Fix type inference for set/delete attr.

Posted by GitBox <gi...@apache.org>.
codecov[bot] commented on PR #23242:
URL: https://github.com/apache/beam/pull/23242#issuecomment-1247424340

   # [Codecov](https://codecov.io/gh/apache/beam/pull/23242?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#23242](https://codecov.io/gh/apache/beam/pull/23242?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (b3a70d2) into [master](https://codecov.io/gh/apache/beam/commit/bb7468ff13683dd82cfe97dff31d82c5a34024c6?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (bb7468f) will **increase** coverage by `0.01%`.
   > The diff coverage is `100.00%`.
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #23242      +/-   ##
   ==========================================
   + Coverage   73.58%   73.59%   +0.01%     
   ==========================================
     Files         716      716              
     Lines       95327    95327              
   ==========================================
   + Hits        70142    70153      +11     
   + Misses      23889    23878      -11     
     Partials     1296     1296              
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | python | `83.41% <100.00%> (+0.01%)` | :arrow_up: |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://codecov.io/gh/apache/beam/pull/23242?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [sdks/python/apache\_beam/typehints/opcodes.py](https://codecov.io/gh/apache/beam/pull/23242/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2Rrcy9weXRob24vYXBhY2hlX2JlYW0vdHlwZWhpbnRzL29wY29kZXMucHk=) | `85.61% <100.00%> (+0.71%)` | :arrow_up: |
   | [...hon/apache\_beam/runners/worker/bundle\_processor.py](https://codecov.io/gh/apache/beam/pull/23242/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2Rrcy9weXRob24vYXBhY2hlX2JlYW0vcnVubmVycy93b3JrZXIvYnVuZGxlX3Byb2Nlc3Nvci5weQ==) | `93.54% <0.00%> (+0.24%)` | :arrow_up: |
   | [sdks/python/apache\_beam/transforms/combiners.py](https://codecov.io/gh/apache/beam/pull/23242/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2Rrcy9weXRob24vYXBhY2hlX2JlYW0vdHJhbnNmb3Jtcy9jb21iaW5lcnMucHk=) | `93.43% <0.00%> (+0.38%)` | :arrow_up: |
   | [...che\_beam/runners/interactive/interactive\_runner.py](https://codecov.io/gh/apache/beam/pull/23242/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2Rrcy9weXRob24vYXBhY2hlX2JlYW0vcnVubmVycy9pbnRlcmFjdGl2ZS9pbnRlcmFjdGl2ZV9ydW5uZXIucHk=) | `91.39% <0.00%> (+1.32%)` | :arrow_up: |
   | [sdks/python/apache\_beam/utils/interactive\_utils.py](https://codecov.io/gh/apache/beam/pull/23242/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2Rrcy9weXRob24vYXBhY2hlX2JlYW0vdXRpbHMvaW50ZXJhY3RpdmVfdXRpbHMucHk=) | `97.56% <0.00%> (+2.43%)` | :arrow_up: |
   | [.../python/apache\_beam/testing/test\_stream\_service.py](https://codecov.io/gh/apache/beam/pull/23242/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2Rrcy9weXRob24vYXBhY2hlX2JlYW0vdGVzdGluZy90ZXN0X3N0cmVhbV9zZXJ2aWNlLnB5) | `92.85% <0.00%> (+4.76%)` | :arrow_up: |
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] robertwb commented on a diff in pull request #23242: Fix type inference for set/delete attr.

Posted by GitBox <gi...@apache.org>.
robertwb commented on code in PR #23242:
URL: https://github.com/apache/beam/pull/23242#discussion_r972200859


##########
sdks/python/apache_beam/typehints/opcodes.py:
##########
@@ -241,8 +241,8 @@ def dup_topx(state, arg):
   state.stack += state[-arg:]
 
 
-store_attr = pop_top
-delete_attr = nop

Review Comment:
   Generally the stack would get messed up and type inference would bail out (returning Any). I was investigating why type inference wasn't working as expected for a cross language transform. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] yeandy commented on a diff in pull request #23242: Fix type inference for set/delete attr.

Posted by GitBox <gi...@apache.org>.
yeandy commented on code in PR #23242:
URL: https://github.com/apache/beam/pull/23242#discussion_r973132246


##########
sdks/python/apache_beam/typehints/trivial_inference_test.py:
##########
@@ -258,6 +258,26 @@ def testGetAttr(self):
         typehints.Tuple[str, typehints.Any],
         lambda: (typehints.__doc__, typehints.fake))
 
+  def testSetAttr(self):
+    def fn(obj, flag):
+      global glob
+      if flag == 1:
+        obj.attr = 1
+        res = 1
+      elif flag == 2:
+        obj.attr = 2
+        res = 1.5
+      elif flag == 3:
+        glob = 3
+        res = "str"
+      elif flag == 4:
+        del glob
+        res = "another str"
+      return res
+    self.assertReturnType(
+        typehints.Union[int, float, str],
+        fn, [int])

Review Comment:
   ```suggestion
   
       self.assertReturnType(typehints.Union[int, float, str],fn, [int])
   ```



##########
sdks/python/apache_beam/typehints/trivial_inference_test.py:
##########
@@ -258,6 +258,26 @@ def testGetAttr(self):
         typehints.Tuple[str, typehints.Any],
         lambda: (typehints.__doc__, typehints.fake))
 
+  def testSetAttr(self):
+    def fn(obj, flag):
+      global glob

Review Comment:
   I see we're getting this lint error: `Global variable 'glob' undefined at the module level (global-variable-undefined)`. Why are we defining a global here? Would defining `glob` outside of `def fn(obj, flag):` fix that? 
   
   I also see there are the `store_global` and `delete_global` opcodes; were you also investigating those?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] yeandy commented on a diff in pull request #23242: Fix type inference for set/delete attr.

Posted by GitBox <gi...@apache.org>.
yeandy commented on code in PR #23242:
URL: https://github.com/apache/beam/pull/23242#discussion_r984663522


##########
sdks/python/apache_beam/typehints/trivial_inference_test.py:
##########
@@ -258,6 +258,26 @@ def testGetAttr(self):
         typehints.Tuple[str, typehints.Any],
         lambda: (typehints.__doc__, typehints.fake))
 
+  def testSetAttr(self):
+    def fn(obj, flag):
+      global glob

Review Comment:
   Makes sense, thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] robertwb commented on pull request #23242: Fix type inference for set/delete attr.

Posted by GitBox <gi...@apache.org>.
robertwb commented on PR #23242:
URL: https://github.com/apache/beam/pull/23242#issuecomment-1247412385

   R: @yeandy


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org