Skip to content

Commit

Permalink
chore: consistently use open() encoding and file descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
nejch authored and JohnVillalovos committed Jan 23, 2022
1 parent 618267c commit dc32d54
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions gitlab/cli.py
Expand Up @@ -257,8 +257,8 @@ def _parse_value(v: Any) -> Any:
# If the user-provided value starts with @, we try to read the file
# path provided after @ as the real value. Exit on any error.
try:
with open(v[1:]) as fl:
return fl.read()
with open(v[1:]) as f:
return f.read()
except Exception as e:
sys.stderr.write(f"{e}\n")
sys.exit(1)
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Expand Up @@ -6,16 +6,16 @@

def get_version() -> str:
version = ""
with open("gitlab/_version.py") as f:
with open("gitlab/_version.py", "r", encoding="utf-8") as f:
for line in f:
if line.startswith("__version__"):
version = eval(line.split("=")[-1])
break
return version


with open("README.rst", "r") as readme_file:
readme = readme_file.read()
with open("README.rst", "r", encoding="utf-8") as f:
readme = f.read()

setup(
name="python-gitlab",
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/conftest.py
Expand Up @@ -87,7 +87,7 @@ def set_token(container, fixture_dir):
logging.info("Creating API token.")
set_token_rb = fixture_dir / "set_token.rb"

with open(set_token_rb, "r") as f:
with open(set_token_rb, "r", encoding="utf-8") as f:
set_token_command = f.read().strip()

rails_command = [
Expand Down Expand Up @@ -206,7 +206,7 @@ def gitlab_config(check_is_alive, docker_ip, docker_services, temp_dir, fixture_
private_token = {token}
api_version = 4"""

with open(config_file, "w") as f:
with open(config_file, "w", encoding="utf-8") as f:
f.write(config)

return config_file
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/objects/test_todos.py
Expand Up @@ -12,8 +12,8 @@

@pytest.fixture()
def json_content(fixture_dir):
with open(fixture_dir / "todo.json", "r") as json_file:
todo_content = json_file.read()
with open(fixture_dir / "todo.json", "r", encoding="utf-8") as f:
todo_content = f.read()
return json.loads(todo_content)


Expand Down

0 comments on commit dc32d54

Please sign in to comment.