Skip to content

Commit e27ac0d

Browse files
PIG208timabbott
authored andcommitted
pyupgrade: Replace Text with str.
We uses `pyupgrade --py3-plus` to automatically replace all occurence of `Text`. But manual fix is required to remove the unused imports. Note that with this configuration pyupgrade also convert string literals to .format(...) style, which is manually not included in the commit as well.
1 parent a54cccc commit e27ac0d

File tree

11 files changed

+42
-46
lines changed

11 files changed

+42
-46
lines changed

zulip/integrations/git/post-receive

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import os
1313
import os.path
1414
import subprocess
1515
import sys
16-
from typing import Text
1716

1817
sys.path.insert(0, os.path.dirname(__file__))
1918
import zulip_git_config as config
@@ -33,7 +32,7 @@ client = zulip.Client(
3332
)
3433

3534

36-
def git_repository_name() -> Text:
35+
def git_repository_name() -> str:
3736
output = subprocess.check_output(["git", "rev-parse", "--is-bare-repository"])
3837
if output.strip() == "true":
3938
return os.path.basename(os.getcwd())[: -len(".git")]

zulip/integrations/git/zulip_git_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
from typing import Dict, Optional, Text
2+
from typing import Dict, Optional
33

44
# Name of the stream to send notifications to, default is "commits"
55
STREAM_NAME = "commits"
@@ -23,7 +23,7 @@
2323
# * stream "commits"
2424
# * topic "master"
2525
# And similarly for branch "test-post-receive" (for use when testing).
26-
def commit_notice_destination(repo: Text, branch: Text, commit: Text) -> Optional[Dict[Text, Text]]:
26+
def commit_notice_destination(repo: str, branch: str, commit: str) -> Optional[Dict[str, str]]:
2727
if branch in ["master", "test-post-receive"]:
2828
return dict(stream=STREAM_NAME, subject="%s" % (branch,))
2929

@@ -36,7 +36,7 @@ def commit_notice_destination(repo: Text, branch: Text, commit: Text) -> Optiona
3636
# graphical repository viewer, e.g.
3737
#
3838
# return '!avatar(%s) [%s](https://example.com/commits/%s)\n' % (author, subject, commit_id)
39-
def format_commit_message(author: Text, subject: Text, commit_id: Text) -> Text:
39+
def format_commit_message(author: str, subject: str, commit_id: str) -> str:
4040
return "!avatar(%s) %s\n" % (author, subject)
4141

4242

zulip/integrations/hg/zulip_changegroup.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# `hg push`). See https://zulip.com/integrations for installation instructions.
77

88
import sys
9-
from typing import Text
109

1110
from mercurial import repository as repo
1211
from mercurial import ui
@@ -17,8 +16,8 @@
1716

1817

1918
def format_summary_line(
20-
web_url: str, user: str, base: int, tip: int, branch: str, node: Text
21-
) -> Text:
19+
web_url: str, user: str, base: int, tip: int, branch: str, node: str
20+
) -> str:
2221
"""
2322
Format the first line of the message, which contains summary
2423
information about the changeset and links to the changelog if a
@@ -71,7 +70,7 @@ def format_commit_lines(web_url: str, repo: repo, base: int, tip: int) -> str:
7170

7271

7372
def send_zulip(
74-
email: str, api_key: str, site: str, stream: str, subject: str, content: Text
73+
email: str, api_key: str, site: str, stream: str, subject: str, content: str
7574
) -> None:
7675
"""
7776
Send a message to Zulip using the provided credentials, which should be for
@@ -100,7 +99,7 @@ def get_config(ui: ui, item: str) -> str:
10099
sys.exit(1)
101100

102101

103-
def hook(ui: ui, repo: repo, **kwargs: Text) -> None:
102+
def hook(ui: ui, repo: repo, **kwargs: str) -> None:
104103
"""
105104
Invoked by configuring a [hook] entry in .hg/hgrc.
106105
"""

zulip/integrations/openshift/zulip_openshift_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# https://github.com/python/mypy/issues/1141
2-
from typing import Dict, Optional, Text
2+
from typing import Dict, Optional
33

44
# Change these values to configure authentication for the plugin
55
ZULIP_USER = "openshift-bot@example.com"
@@ -19,7 +19,7 @@
1919
# * stream "deployments"
2020
# * topic "master"
2121
# And similarly for branch "test-post-receive" (for use when testing).
22-
def deployment_notice_destination(branch: str) -> Optional[Dict[str, Text]]:
22+
def deployment_notice_destination(branch: str) -> Optional[Dict[str, str]]:
2323
if branch in ["master", "test-post-receive"]:
2424
return dict(stream="deployments", subject="%s" % (branch,))
2525

zulip/integrations/perforce/zulip_perforce_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, Optional, Text
1+
from typing import Dict, Optional
22

33
# Change these values to configure authentication for the plugin
44
ZULIP_USER = "p4-bot@example.com"
@@ -28,7 +28,7 @@
2828
# "master-plan" and "secret" subdirectories of //depot/ to:
2929
# * stream "depot_subdirectory-commits"
3030
# * subject "change_root"
31-
def commit_notice_destination(path: Text, changelist: int) -> Optional[Dict[Text, Text]]:
31+
def commit_notice_destination(path: str, changelist: int) -> Optional[Dict[str, str]]:
3232
dirs = path.split("/")
3333
if len(dirs) >= 4 and dirs[3] not in ("*", "..."):
3434
directory = dirs[3]

zulip/integrations/svn/zulip_svn_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, Optional, Text
1+
from typing import Dict, Optional
22

33
# Change these values to configure authentication for the plugin
44
ZULIP_USER = "svn-bot@example.com"
@@ -18,7 +18,7 @@
1818
# and "my-super-secret-repository" repos to
1919
# * stream "commits"
2020
# * topic "branch_name"
21-
def commit_notice_destination(path: Text, commit: Text) -> Optional[Dict[Text, Text]]:
21+
def commit_notice_destination(path: str, commit: str) -> Optional[Dict[str, str]]:
2222
repo = path.split("/")[-1]
2323
if repo not in ["evil-master-plan", "my-super-secret-repository"]:
2424
return dict(stream="commits", subject="%s" % (repo,))

zulip/zulip/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
Mapping,
2323
Optional,
2424
Sequence,
25-
Text,
2625
Tuple,
2726
Union,
2827
)
@@ -313,7 +312,7 @@ def get_default_config_filename() -> Optional[str]:
313312
return config_file
314313

315314

316-
def validate_boolean_field(field: Optional[Text]) -> Union[bool, None]:
315+
def validate_boolean_field(field: Optional[str]) -> Union[bool, None]:
317316
if not isinstance(field, str):
318317
return None
319318

@@ -563,7 +562,7 @@ def do_api_query(
563562
req_files = []
564563

565564
for (key, val) in orig_request.items():
566-
if isinstance(val, str) or isinstance(val, Text):
565+
if isinstance(val, str) or isinstance(val, str):
567566
request[key] = val
568567
else:
569568
request[key] = json.dumps(val)

zulip_bots/zulip_bots/bots/monkeytestit/lib/parse.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
"""
44

55
from json.decoder import JSONDecodeError
6-
from typing import Text
76

87
from zulip_bots.bots.monkeytestit.lib import extract, report
98

109

11-
def execute(message: Text, apikey: Text) -> Text:
10+
def execute(message: str, apikey: str) -> str:
1211
"""Parses message and returns a dictionary
1312
1413
:param message: The message
@@ -69,7 +68,7 @@ def execute(message: Text, apikey: Text) -> Text:
6968
return "Unknown command. Available commands: `check <website> " "[params]`"
7069

7170

72-
def failed(message: Text) -> Text:
71+
def failed(message: str) -> str:
7372
"""Simply attaches a failed marker to a message
7473
7574
:param message: The message

zulip_bots/zulip_bots/bots/monkeytestit/lib/report.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""Used to mainly compose a decorated report for the user
22
"""
33

4-
from typing import Dict, List, Text
4+
from typing import Dict, List
55

66

7-
def compose(results: Dict) -> Text:
7+
def compose(results: Dict) -> str:
88
"""Composes a report based on test results
99
1010
An example would be:
@@ -38,7 +38,7 @@ def compose(results: Dict) -> Text:
3838
return response
3939

4040

41-
def print_more_info_url(results: Dict) -> Text:
41+
def print_more_info_url(results: Dict) -> str:
4242
"""Creates info for the test URL from monkeytest.it
4343
4444
Example:
@@ -51,7 +51,7 @@ def print_more_info_url(results: Dict) -> Text:
5151
return "More info: {}".format(results["results_url"])
5252

5353

54-
def print_test_id(results: Dict) -> Text:
54+
def print_test_id(results: Dict) -> str:
5555
"""Prints the test-id with attached to the url
5656
5757
:param results: A dictionary containing the results of a check
@@ -60,7 +60,7 @@ def print_test_id(results: Dict) -> Text:
6060
return "Test: https://monkeytest.it/test/{}".format(results["test_id"])
6161

6262

63-
def print_failures_checkers(results: Dict) -> Text:
63+
def print_failures_checkers(results: Dict) -> str:
6464
"""Creates info for failures in enabled checkers
6565
6666
Example:
@@ -105,7 +105,7 @@ def get_enabled_checkers(results: Dict) -> List:
105105
return enabled_checkers
106106

107107

108-
def print_enabled_checkers(results: Dict) -> Text:
108+
def print_enabled_checkers(results: Dict) -> str:
109109
"""Creates info for enabled checkers. This joins the list of enabled
110110
checkers and format it with the current string response
111111
@@ -118,7 +118,7 @@ def print_enabled_checkers(results: Dict) -> Text:
118118
return "Enabled checkers: {}".format(", ".join(get_enabled_checkers(results)))
119119

120120

121-
def print_status(results: Dict) -> Text:
121+
def print_status(results: Dict) -> str:
122122
"""Creates info for the check status.
123123
124124
Example: Status: tests_failed

zulip_bots/zulip_bots/finder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import importlib.util
44
import os
55
from pathlib import Path
6-
from typing import Any, Optional, Text, Tuple
6+
from typing import Any, Optional, Tuple
77

88
current_dir = os.path.dirname(os.path.abspath(__file__))
99

1010

11-
def import_module_from_source(path: Text, name: Text) -> Any:
11+
def import_module_from_source(path: str, name: str) -> Any:
1212
spec = importlib.util.spec_from_file_location(name, path)
1313
module = importlib.util.module_from_spec(spec)
1414
loader = spec.loader
@@ -18,14 +18,14 @@ def import_module_from_source(path: Text, name: Text) -> Any:
1818
return module
1919

2020

21-
def import_module_by_name(name: Text) -> Any:
21+
def import_module_by_name(name: str) -> Any:
2222
try:
2323
return importlib.import_module(name)
2424
except ImportError:
2525
return None
2626

2727

28-
def resolve_bot_path(name: Text) -> Optional[Tuple[Path, Text]]:
28+
def resolve_bot_path(name: str) -> Optional[Tuple[Path, str]]:
2929
if os.path.isfile(name):
3030
bot_path = Path(name)
3131
bot_name = Path(bot_path).stem

zulip_bots/zulip_bots/lib.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sys
88
import time
99
from contextlib import contextmanager
10-
from typing import IO, Any, Dict, Iterator, List, Optional, Set, Text
10+
from typing import IO, Any, Dict, Iterator, List, Optional, Set
1111

1212
from typing_extensions import Protocol
1313

@@ -79,13 +79,13 @@ def __init__(self, name: str, email: str) -> None:
7979

8080

8181
class BotStorage(Protocol):
82-
def put(self, key: Text, value: Any) -> None:
82+
def put(self, key: str, value: Any) -> None:
8383
...
8484

85-
def get(self, key: Text) -> Any:
85+
def get(self, key: str) -> Any:
8686
...
8787

88-
def contains(self, key: Text) -> bool:
88+
def contains(self, key: str) -> bool:
8989
...
9090

9191

@@ -100,13 +100,13 @@ def __init__(self, parent_storage: BotStorage, init_data: Dict[str, Any]) -> Non
100100
self._cache = init_data
101101
self._dirty_keys: Set[str] = set()
102102

103-
def put(self, key: Text, value: Any) -> None:
103+
def put(self, key: str, value: Any) -> None:
104104
# In the cached storage, values being put to the storage is not flushed to the parent storage.
105105
# It will be marked dirty until it get flushed.
106106
self._cache[key] = value
107107
self._dirty_keys.add(key)
108108

109-
def get(self, key: Text) -> Any:
109+
def get(self, key: str) -> Any:
110110
# Unless the key is not found in the cache, the cached storage will not lookup the parent storage.
111111
if key in self._cache:
112112
return self._cache[key]
@@ -123,11 +123,11 @@ def flush(self) -> None:
123123
key = self._dirty_keys.pop()
124124
self._parent_storage.put(key, self._cache[key])
125125

126-
def flush_one(self, key: Text) -> None:
126+
def flush_one(self, key: str) -> None:
127127
self._dirty_keys.remove(key)
128128
self._parent_storage.put(key, self._cache[key])
129129

130-
def contains(self, key: Text) -> bool:
130+
def contains(self, key: str) -> bool:
131131
if key in self._cache:
132132
return True
133133
else:
@@ -139,15 +139,15 @@ def __init__(self, client: Client) -> None:
139139
self._client = client
140140
self.marshal = lambda obj: json.dumps(obj)
141141
self.demarshal = lambda obj: json.loads(obj)
142-
self.state_ = dict() # type: Dict[Text, Any]
142+
self.state_ = dict()
143143

144-
def put(self, key: Text, value: Any) -> None:
144+
def put(self, key: str, value: Any) -> None:
145145
self.state_[key] = self.marshal(value)
146146
response = self._client.update_storage({"storage": {key: self.state_[key]}})
147147
if response["result"] != "success":
148148
raise StateHandlerError("Error updating state: {}".format(str(response)))
149149

150-
def get(self, key: Text) -> Any:
150+
def get(self, key: str) -> Any:
151151
if key in self.state_:
152152
return self.demarshal(self.state_[key])
153153

@@ -159,12 +159,12 @@ def get(self, key: Text) -> Any:
159159
self.state_[key] = marshalled_value
160160
return self.demarshal(marshalled_value)
161161

162-
def contains(self, key: Text) -> bool:
162+
def contains(self, key: str) -> bool:
163163
return key in self.state_
164164

165165

166166
@contextmanager
167-
def use_storage(storage: BotStorage, keys: List[Text]) -> Iterator[BotStorage]:
167+
def use_storage(storage: BotStorage, keys: List[str]) -> Iterator[BotStorage]:
168168
# The context manager for StateHandler that minimizes the number of round-trips to the server.
169169
# It will fetch all the data using the specified keys and store them to
170170
# a CachedStorage that will not communicate with the server until manually

0 commit comments

Comments
 (0)