You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "jrmccluskey (via GitHub)" <gi...@apache.org> on 2023/05/30 15:34:30 UTC
[GitHub] [beam] jrmccluskey commented on a diff in pull request #26290: Inherit Generic for TimestampedValue
jrmccluskey commented on code in PR #26290:
URL: https://github.com/apache/beam/pull/26290#discussion_r1210443461
##########
sdks/python/apache_beam/transforms/timestamped_value_type_test.py:
##########
@@ -0,0 +1,99 @@
+from apache_beam.typehints import Dict, Any, List
Review Comment:
This will fix the RAT PreCommit
##########
sdks/python/apache_beam/transforms/window.py:
##########
@@ -55,6 +55,8 @@
from typing import Iterable
from typing import List
from typing import Optional
+from typing import Generic
Review Comment:
the Generic type import should be after the `Any`, I'd make a suggestion for it but the UI doesn't want me doing multiline suggestions outside of lines you've touched in the PR
##########
sdks/python/apache_beam/transforms/timestamped_value_type_test.py:
##########
@@ -0,0 +1,99 @@
+from apache_beam.typehints import Dict, Any, List
+from apache_beam.typehints.decorators import TypeCheckError
+from apache_beam.transforms.window import TimestampedValue
+
+import unittest
+import apache_beam as beam
Review Comment:
This fixes the RAT precommit and linting errors
##########
sdks/python/apache_beam/transforms/timestamped_value_type_test.py:
##########
@@ -0,0 +1,99 @@
+from apache_beam.typehints import Dict, Any, List
+from apache_beam.typehints.decorators import TypeCheckError
+from apache_beam.transforms.window import TimestampedValue
+
+import unittest
+import apache_beam as beam
+
+
+def ConvertToTimestampedValue(plant: Dict[str, Any]) -> TimestampedValue[str]:
+ return TimestampedValue[str](plant["name"], plant["season"])
+
+
+def ConvertToTimestampedValue_1(plant: Dict[str, Any]) -> TimestampedValue:
+ return TimestampedValue(plant["name"], plant["season"])
+
+
+def ConvertToTimestampedValue_2(
+ plant: Dict[str, Any]) -> TimestampedValue[List[str]]:
Review Comment:
This test case is failing:
```
____ ERROR collecting apache_beam/transforms/timestamped_value_type_test.py ____
17:08:32 apache_beam/transforms/timestamped_value_type_test.py:18: in <module>
17:08:32 plant: Dict[str, Any]) -> TimestampedValue[List[str]]:
17:08:32 /usr/lib/python3.8/typing.py:261: in inner
17:08:32 return func(*args, **kwds)
17:08:32 /usr/lib/python3.8/typing.py:886: in __class_getitem__
17:08:32 params = tuple(_type_check(p, msg) for p in params)
17:08:32 /usr/lib/python3.8/typing.py:886: in <genexpr>
17:08:32 params = tuple(_type_check(p, msg) for p in params)
17:08:32 /usr/lib/python3.8/typing.py:149: in _type_check
17:08:32 raise TypeError(f"{msg} Got {arg!r:.100}.")
17:08:32 E TypeError: Parameters to generic types must be types. Got List[<class 'str'>].
```
##########
sdks/python/apache_beam/transforms/timestamped_value_type_test.py:
##########
@@ -0,0 +1,99 @@
+from apache_beam.typehints import Dict, Any, List
+from apache_beam.typehints.decorators import TypeCheckError
+from apache_beam.transforms.window import TimestampedValue
+
+import unittest
+import apache_beam as beam
Review Comment:
```suggestion
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import unittest
import apache_beam as beam
from apache_beam.transforms.window import TimestampedValue
from apache_beam.typehints import Any
from apache_beam.typehints import Dict
from apache_beam.typehints import List
from apache_beam.typehints.decorators import TypeCheckError
```
--
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