TheNeuralBit commented on code in PR #23361: URL: https://github.com/apache/beam/pull/23361#discussion_r995224297
########## sdks/python/apache_beam/typehints/testing/strategies.py: ########## @@ -0,0 +1,102 @@ +# +# 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. +# + +"""hypothesis strategies for generating schema types. + +Intended for internal use only, no backward-compatibility guarantees.""" + +import keyword +import unicodedata +from typing import Mapping +from typing import Optional +from typing import Sequence + +from hypothesis import strategies as st + +from apache_beam.typehints import row_type +from apache_beam.typehints.schemas import _PRIMITIVES + +PRIMITIVES = [p[0] for p in _PRIMITIVES] + + +def field_names(): + @st.composite + def field_name_candidates(draw): + """Strategy to produce valid field names for Beam schema types.""" + # unicode categories that cannot be used in Python identifiers + identifer_denylist = ( + 'Lo', 'Lm', 'C', 'P', 'Sm', 'Sc', 'So', 'Sk', 'M', 'No', 'Z') + + # First character can't be numeric (Nd). + # It also can't start with '_' in a NamedTuple. + field_first_character = draw( + st.text( + alphabet=st.characters( + blacklist_categories=('Nd', ) + identifer_denylist, + blacklist_characters=('_')), + min_size=1, + max_size=1)) + field_remainder = draw( + st.text( + alphabet=st.characters(blacklist_categories=identifer_denylist))) + + return field_first_character + field_remainder Review Comment: That is handled outside of this composite, see the next couple of lines with the `filter()` on `isidentifier` and `iskeyword` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
