diff --git a/language/snippets/api/analyze_test.py b/language/snippets/api/analyze_test.py index c797e2e3364c..da5f0ab0c4d9 100644 --- a/language/snippets/api/analyze_test.py +++ b/language/snippets/api/analyze_test.py @@ -48,7 +48,7 @@ def test_analyze_sentiment(capsys): def test_analyze_syntax(capsys): result = analyze.analyze_syntax( textwrap.dedent( - u"""\ + """\ Keep away from people who try to belittle your ambitions. Small people always do that, but the really great make you feel that you, too, can become great. @@ -71,7 +71,7 @@ def test_analyze_syntax_utf8(): bits. The offsets we get should be the index of the first byte of the character. """ - test_string = u"a \u00e3 \u0201 \U0001f636 b" + test_string = "a \u00e3 \u0201 \U0001f636 b" byte_array = test_string.encode("utf8") result = analyze.analyze_syntax(test_string, encoding="UTF8") tokens = result["tokens"] @@ -82,19 +82,19 @@ def test_analyze_syntax_utf8(): byte_array[offset : offset + 1].decode("utf8") == tokens[0]["text"]["content"] ) - assert tokens[1]["text"]["content"] == u"\u00e3" + assert tokens[1]["text"]["content"] == "\u00e3" offset = tokens[1]["text"].get("beginOffset", 0) assert ( byte_array[offset : offset + 2].decode("utf8") == tokens[1]["text"]["content"] ) - assert tokens[2]["text"]["content"] == u"\u0201" + assert tokens[2]["text"]["content"] == "\u0201" offset = tokens[2]["text"].get("beginOffset", 0) assert ( byte_array[offset : offset + 2].decode("utf8") == tokens[2]["text"]["content"] ) - assert tokens[3]["text"]["content"] == u"\U0001f636" + assert tokens[3]["text"]["content"] == "\U0001f636" offset = tokens[3]["text"].get("beginOffset", 0) assert ( byte_array[offset : offset + 4].decode("utf8") == tokens[3]["text"]["content"] @@ -102,7 +102,7 @@ def test_analyze_syntax_utf8(): # This demonstrates that the offset takes into account the variable-length # characters before the target token. - assert tokens[4]["text"]["content"] == u"b" + assert tokens[4]["text"]["content"] == "b" offset = tokens[4]["text"].get("beginOffset", 0) # 'b' is only one byte long assert ( @@ -117,7 +117,7 @@ def test_analyze_syntax_utf16(): bits. The returned offsets will be the index of the first 2-byte character of the token. """ - test_string = u"a \u00e3 \u0201 \U0001f636 b" + test_string = "a \u00e3 \u0201 \U0001f636 b" byte_array = test_string.encode("utf16") # Remove the byte order marker, which the offsets don't account for byte_array = byte_array[2:] @@ -133,7 +133,7 @@ def test_analyze_syntax_utf16(): byte_array[offset : offset + 2].decode("utf16") == tokens[0]["text"]["content"] ) - assert tokens[1]["text"]["content"] == u"\u00e3" + assert tokens[1]["text"]["content"] == "\u00e3" offset = 2 * tokens[1]["text"].get("beginOffset", 0) # A UTF16 character with a low codepoint is 16 bits (2 bytes) long, so # slice out 2 bytes starting from the offset. Then interpret the bytes as @@ -142,7 +142,7 @@ def test_analyze_syntax_utf16(): byte_array[offset : offset + 2].decode("utf16") == tokens[1]["text"]["content"] ) - assert tokens[2]["text"]["content"] == u"\u0201" + assert tokens[2]["text"]["content"] == "\u0201" offset = 2 * tokens[2]["text"].get("beginOffset", 0) # A UTF16 character with a low codepoint is 16 bits (2 bytes) long, so # slice out 2 bytes starting from the offset. Then interpret the bytes as @@ -151,7 +151,7 @@ def test_analyze_syntax_utf16(): byte_array[offset : offset + 2].decode("utf16") == tokens[2]["text"]["content"] ) - assert tokens[3]["text"]["content"] == u"\U0001f636" + assert tokens[3]["text"]["content"] == "\U0001f636" offset = 2 * tokens[3]["text"].get("beginOffset", 0) # A UTF16 character with a high codepoint is 32 bits (4 bytes) long, so # slice out 4 bytes starting from the offset. Then interpret those bytes as @@ -162,7 +162,7 @@ def test_analyze_syntax_utf16(): # This demonstrates that the offset takes into account the variable-length # characters before the target token. - assert tokens[4]["text"]["content"] == u"b" + assert tokens[4]["text"]["content"] == "b" offset = 2 * tokens[4]["text"].get("beginOffset", 0) # Even though 'b' is only one byte long, utf16 still encodes it using 16 # bits @@ -192,7 +192,7 @@ def test_annotate_text_utf32(): unicode object with the raw offset returned by the api (ie without multiplying it by 4, as it is below). """ - test_string = u"a \u00e3 \u0201 \U0001f636 b" + test_string = "a \u00e3 \u0201 \U0001f636 b" byte_array = test_string.encode("utf32") # Remove the byte order marker, which the offsets don't account for byte_array = byte_array[4:] @@ -208,7 +208,7 @@ def test_annotate_text_utf32(): byte_array[offset : offset + 4].decode("utf32") == tokens[0]["text"]["content"] ) - assert tokens[1]["text"]["content"] == u"\u00e3" + assert tokens[1]["text"]["content"] == "\u00e3" offset = 4 * tokens[1]["text"].get("beginOffset", 0) # A UTF32 character with a low codepoint is 32 bits (4 bytes) long, so # slice out 4 bytes starting from the offset. Then interpret the bytes as @@ -217,7 +217,7 @@ def test_annotate_text_utf32(): byte_array[offset : offset + 4].decode("utf32") == tokens[1]["text"]["content"] ) - assert tokens[2]["text"]["content"] == u"\u0201" + assert tokens[2]["text"]["content"] == "\u0201" offset = 4 * tokens[2]["text"].get("beginOffset", 0) # A UTF32 character with a low codepoint is 32 bits (4 bytes) long, so # slice out 4 bytes starting from the offset. Then interpret the bytes as @@ -226,7 +226,7 @@ def test_annotate_text_utf32(): byte_array[offset : offset + 4].decode("utf32") == tokens[2]["text"]["content"] ) - assert tokens[3]["text"]["content"] == u"\U0001f636" + assert tokens[3]["text"]["content"] == "\U0001f636" offset = 4 * tokens[3]["text"].get("beginOffset", 0) # A UTF32 character with a high codepoint is 32 bits (4 bytes) long, so # slice out 4 bytes starting from the offset. Then interpret those bytes as @@ -237,7 +237,7 @@ def test_annotate_text_utf32(): # This demonstrates that the offset takes into account the variable-length # characters before the target token. - assert tokens[4]["text"]["content"] == u"b" + assert tokens[4]["text"]["content"] == "b" offset = 4 * tokens[4]["text"].get("beginOffset", 0) # Even though 'b' is only one byte long, utf32 still encodes it using 32 # bits @@ -252,7 +252,7 @@ def test_annotate_text_utf32_directly_index_into_unicode(): See the explanation for test_annotate_text_utf32. Essentially, indexing into a utf32 array is equivalent to indexing into a python unicode object. """ - test_string = u"a \u00e3 \u0201 \U0001f636 b" + test_string = "a \u00e3 \u0201 \U0001f636 b" result = analyze.analyze_syntax(test_string, encoding="UTF32") tokens = result["tokens"] @@ -260,11 +260,11 @@ def test_annotate_text_utf32_directly_index_into_unicode(): offset = tokens[0]["text"].get("beginOffset", 0) assert test_string[offset] == tokens[0]["text"]["content"] - assert tokens[1]["text"]["content"] == u"\u00e3" + assert tokens[1]["text"]["content"] == "\u00e3" offset = tokens[1]["text"].get("beginOffset", 0) assert test_string[offset] == tokens[1]["text"]["content"] - assert tokens[2]["text"]["content"] == u"\u0201" + assert tokens[2]["text"]["content"] == "\u0201" offset = tokens[2]["text"].get("beginOffset", 0) assert test_string[offset] == tokens[2]["text"]["content"] diff --git a/language/snippets/api/noxfile.py b/language/snippets/api/noxfile.py index 85f5836dba3a..25f87a215d4c 100644 --- a/language/snippets/api/noxfile.py +++ b/language/snippets/api/noxfile.py @@ -29,7 +29,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" # Copy `noxfile_config.py` to your directory and modify it instead. @@ -253,7 +253,7 @@ def py(session: nox.sessions.Session) -> None: def _get_repo_root() -> Optional[str]: - """ Returns the root folder of the project. """ + """Returns the root folder of the project.""" # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) for i in range(10): diff --git a/language/snippets/classify_text/classify_text_tutorial.py b/language/snippets/classify_text/classify_text_tutorial.py index 675f8499efc0..de35451dd0f7 100644 --- a/language/snippets/classify_text/classify_text_tutorial.py +++ b/language/snippets/classify_text/classify_text_tutorial.py @@ -35,7 +35,7 @@ # [START language_classify_text_tutorial_classify] def classify(text, verbose=True): - """Classify the input text into categories. """ + """Classify the input text into categories.""" language_client = language_v1.LanguageServiceClient() @@ -56,9 +56,9 @@ def classify(text, verbose=True): if verbose: print(text) for category in categories: - print(u"=" * 20) - print(u"{:<16}: {}".format("category", category.name)) - print(u"{:<16}: {}".format("confidence", category.confidence)) + print("=" * 20) + print("{:<16}: {}".format("category", category.name)) + print("{:<16}: {}".format("confidence", category.confidence)) return result diff --git a/language/snippets/classify_text/noxfile.py b/language/snippets/classify_text/noxfile.py index 85f5836dba3a..25f87a215d4c 100644 --- a/language/snippets/classify_text/noxfile.py +++ b/language/snippets/classify_text/noxfile.py @@ -29,7 +29,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" # Copy `noxfile_config.py` to your directory and modify it instead. @@ -253,7 +253,7 @@ def py(session: nox.sessions.Session) -> None: def _get_repo_root() -> Optional[str]: - """ Returns the root folder of the project. """ + """Returns the root folder of the project.""" # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) for i in range(10): diff --git a/language/snippets/cloud-client/v1/noxfile.py b/language/snippets/cloud-client/v1/noxfile.py index 85f5836dba3a..25f87a215d4c 100644 --- a/language/snippets/cloud-client/v1/noxfile.py +++ b/language/snippets/cloud-client/v1/noxfile.py @@ -29,7 +29,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" # Copy `noxfile_config.py` to your directory and modify it instead. @@ -253,7 +253,7 @@ def py(session: nox.sessions.Session) -> None: def _get_repo_root() -> Optional[str]: - """ Returns the root folder of the project. """ + """Returns the root folder of the project.""" # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) for i in range(10): diff --git a/language/snippets/cloud-client/v1/quickstart.py b/language/snippets/cloud-client/v1/quickstart.py index b9b0e96c1781..59c1cd435cc2 100644 --- a/language/snippets/cloud-client/v1/quickstart.py +++ b/language/snippets/cloud-client/v1/quickstart.py @@ -29,7 +29,7 @@ def run_quickstart(): # [END language_python_migration_client] # The text to analyze - text = u"Hello, world!" + text = "Hello, world!" document = language_v1.Document( content=text, type_=language_v1.Document.Type.PLAIN_TEXT ) diff --git a/language/snippets/generated-samples/v1/noxfile.py b/language/snippets/generated-samples/v1/noxfile.py index 85f5836dba3a..25f87a215d4c 100644 --- a/language/snippets/generated-samples/v1/noxfile.py +++ b/language/snippets/generated-samples/v1/noxfile.py @@ -29,7 +29,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" # Copy `noxfile_config.py` to your directory and modify it instead. @@ -253,7 +253,7 @@ def py(session: nox.sessions.Session) -> None: def _get_repo_root() -> Optional[str]: - """ Returns the root folder of the project. """ + """Returns the root folder of the project.""" # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) for i in range(10): diff --git a/language/snippets/sentiment/noxfile.py b/language/snippets/sentiment/noxfile.py index 85f5836dba3a..25f87a215d4c 100644 --- a/language/snippets/sentiment/noxfile.py +++ b/language/snippets/sentiment/noxfile.py @@ -29,7 +29,7 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -BLACK_VERSION = "black==19.10b0" +BLACK_VERSION = "black==22.3.0" # Copy `noxfile_config.py` to your directory and modify it instead. @@ -253,7 +253,7 @@ def py(session: nox.sessions.Session) -> None: def _get_repo_root() -> Optional[str]: - """ Returns the root folder of the project. """ + """Returns the root folder of the project.""" # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) for i in range(10):