Skip to content

Commit 1081d59

Browse files
Remove previous workarounds for when super() could not be pickled on Py3 (#39187)
* Remove the workaround for pickle * Remove the workaround for pickle
1 parent 63aecf2 commit 1081d59

9 files changed

Lines changed: 31 additions & 57 deletions

File tree

sdks/python/apache_beam/examples/complete/autocomplete.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ def format_result(prefix_candidates):
5858

5959
class TopPerPrefix(beam.PTransform):
6060
def __init__(self, count):
61-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
62-
# super().__init__()
63-
beam.PTransform.__init__(self)
61+
super().__init__()
62+
6463
self._count = count
6564

6665
def expand(self, words):

sdks/python/apache_beam/examples/complete/game/game_stats.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ class ParseGameEventFn(beam.DoFn):
105105
The human-readable time string is not used here.
106106
"""
107107
def __init__(self):
108-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
109-
# super().__init__()
110-
beam.DoFn.__init__(self)
108+
super().__init__()
111109
self.num_parse_errors = Metrics.counter(self.__class__, 'num_parse_errors')
112110

113111
def process(self, elem):
@@ -131,9 +129,8 @@ class ExtractAndSumScore(beam.PTransform):
131129
extracted.
132130
"""
133131
def __init__(self, field):
134-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
135-
# super().__init__()
136-
beam.PTransform.__init__(self)
132+
super().__init__()
133+
137134
self.field = field
138135

139136
def expand(self, pcoll):
@@ -171,9 +168,8 @@ def __init__(self, table_name, dataset, schema, project):
171168
schema: Dictionary in the format {'column_name': 'bigquery_type'}
172169
project: Name of the Cloud project containing BigQuery table.
173170
"""
174-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
175-
# super().__init__()
176-
beam.PTransform.__init__(self)
171+
super().__init__()
172+
177173
self.table_name = table_name
178174
self.dataset = dataset
179175
self.schema = schema

sdks/python/apache_beam/examples/complete/game/hourly_team_score.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ class ParseGameEventFn(beam.DoFn):
105105
The human-readable time string is not used here.
106106
"""
107107
def __init__(self):
108-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
109-
# super().__init__()
110-
beam.DoFn.__init__(self)
108+
super().__init__()
111109
self.num_parse_errors = Metrics.counter(self.__class__, 'num_parse_errors')
112110

113111
def process(self, elem):
@@ -131,9 +129,8 @@ class ExtractAndSumScore(beam.PTransform):
131129
extracted.
132130
"""
133131
def __init__(self, field):
134-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
135-
# super().__init__()
136-
beam.PTransform.__init__(self)
132+
super().__init__()
133+
137134
self.field = field
138135

139136
def expand(self, pcoll):
@@ -171,9 +168,8 @@ def __init__(self, table_name, dataset, schema, project):
171168
schema: Dictionary in the format {'column_name': 'bigquery_type'}
172169
project: Name of the Cloud project containing BigQuery table.
173170
"""
174-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
175-
# super().__init__()
176-
beam.PTransform.__init__(self)
171+
super().__init__()
172+
177173
self.table_name = table_name
178174
self.dataset = dataset
179175
self.schema = schema
@@ -196,9 +192,8 @@ def expand(self, pcoll):
196192
# [START main]
197193
class HourlyTeamScore(beam.PTransform):
198194
def __init__(self, start_min, stop_min, window_duration):
199-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
200-
# super().__init__()
201-
beam.PTransform.__init__(self)
195+
super().__init__()
196+
202197
self.start_timestamp = str2timestamp(start_min)
203198
self.stop_timestamp = str2timestamp(stop_min)
204199
self.window_duration_in_seconds = window_duration * 60

sdks/python/apache_beam/examples/complete/game/leader_board.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ class ParseGameEventFn(beam.DoFn):
114114
The human-readable time string is not used here.
115115
"""
116116
def __init__(self):
117-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
118-
# super().__init__()
119-
beam.DoFn.__init__(self)
117+
super().__init__()
120118
self.num_parse_errors = Metrics.counter(self.__class__, 'num_parse_errors')
121119

122120
def process(self, elem):
@@ -140,9 +138,8 @@ class ExtractAndSumScore(beam.PTransform):
140138
extracted.
141139
"""
142140
def __init__(self, field):
143-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
144-
# super().__init__()
145-
beam.PTransform.__init__(self)
141+
super().__init__()
142+
146143
self.field = field
147144

148145
def expand(self, pcoll):
@@ -180,9 +177,8 @@ def __init__(self, table_name, dataset, schema, project):
180177
schema: Dictionary in the format {'column_name': 'bigquery_type'}
181178
project: Name of the Cloud project containing BigQuery table.
182179
"""
183-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
184-
# super().__init__()
185-
beam.PTransform.__init__(self)
180+
super().__init__()
181+
186182
self.table_name = table_name
187183
self.dataset = dataset
188184
self.schema = schema
@@ -210,9 +206,8 @@ class CalculateTeamScores(beam.PTransform):
210206
default.
211207
"""
212208
def __init__(self, team_window_duration, allowed_lateness):
213-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
214-
# super().__init__()
215-
beam.PTransform.__init__(self)
209+
super().__init__()
210+
216211
self.team_window_duration = team_window_duration * 60
217212
self.allowed_lateness_seconds = allowed_lateness * 60
218213

@@ -242,9 +237,8 @@ class CalculateUserScores(beam.PTransform):
242237
global windowing. Get periodic updates on all users' running scores.
243238
"""
244239
def __init__(self, allowed_lateness):
245-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
246-
# super().__init__()
247-
beam.PTransform.__init__(self)
240+
super().__init__()
241+
248242
self.allowed_lateness_seconds = allowed_lateness * 60
249243

250244
def expand(self, pcoll):

sdks/python/apache_beam/examples/complete/game/user_score.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,7 @@ class ParseGameEventFn(beam.DoFn):
9797
The human-readable time string is not used here.
9898
"""
9999
def __init__(self):
100-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
101-
# super().__init__()
102-
beam.DoFn.__init__(self)
100+
super().__init__()
103101
self.num_parse_errors = Metrics.counter(self.__class__, 'num_parse_errors')
104102

105103
def process(self, elem):
@@ -124,9 +122,8 @@ class ExtractAndSumScore(beam.PTransform):
124122
extracted.
125123
"""
126124
def __init__(self, field):
127-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
128-
# super().__init__()
129-
beam.PTransform.__init__(self)
125+
super().__init__()
126+
130127
self.field = field
131128

132129
def expand(self, pcoll):

sdks/python/apache_beam/examples/complete/top_wikipedia_sessions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ def format_output(element, window=beam.DoFn.WindowParam):
111111
class ComputeTopSessions(beam.PTransform):
112112
"""Computes the top user sessions for each month."""
113113
def __init__(self, sampling_threshold):
114-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
115-
# super().__init__()
116-
beam.PTransform.__init__(self)
114+
super().__init__()
115+
117116
self.sampling_threshold = sampling_threshold
118117

119118
def expand(self, pcoll):

sdks/python/apache_beam/examples/cookbook/bigtableio_it_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ class GenerateTestRows(beam.PTransform):
6666
6767
"""
6868
def __init__(self, number, project_id=None, instance_id=None, table_id=None):
69-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
70-
# super().__init__()
71-
beam.PTransform.__init__(self)
69+
super().__init__()
7270
self.number = number
7371
self.rand = random.choice(string.ascii_letters + string.digits)
7472
self.column_family_id = 'cf1'

sdks/python/apache_beam/examples/wordcount_debugging.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@
7979
class FilterTextFn(beam.DoFn):
8080
"""A DoFn that filters for a specific key based on a regular expression."""
8181
def __init__(self, pattern):
82-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
83-
# super().__init__()
84-
beam.DoFn.__init__(self)
82+
super().__init__()
8583
self.pattern = pattern
8684
# A custom metric can track values in your pipeline as it runs. Those
8785
# values will be available in the monitoring system of the runner used

sdks/python/apache_beam/examples/wordcount_with_metrics.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@
5353
class WordExtractingDoFn(beam.DoFn):
5454
"""Parse each line of input text into words."""
5555
def __init__(self):
56-
# TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3.
57-
# super().__init__()
58-
beam.DoFn.__init__(self)
56+
super().__init__()
5957
self.words_counter = Metrics.counter(self.__class__, 'words')
6058
self.word_lengths_counter = Metrics.counter(self.__class__, 'word_lengths')
6159
self.word_lengths_dist = Metrics.distribution(

0 commit comments

Comments
 (0)