Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate to_str #3298

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions poetry/repositories/pypi_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from poetry.core.version.markers import parse_marker
from poetry.locations import REPOSITORY_CACHE_DIR
from poetry.utils._compat import Path
from poetry.utils._compat import to_str
from poetry.utils.helpers import download_file
from poetry.utils.helpers import temporary_directory
from poetry.utils.patterns import wheel_file_re
Expand Down Expand Up @@ -181,7 +180,7 @@ def search(self, query):

try:
result = Package(name, version, description)
result.description = to_str(description.strip())
result.description = str(description.strip())
results.append(result)
except ParseVersionError:
self._log(
Expand Down
20 changes: 0 additions & 20 deletions poetry/utils/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,26 +263,6 @@ def encode(string, encodings=None):
return string.encode(encodings[0], errors="ignore")


def to_str(string):
if isinstance(string, str) or not isinstance(string, (unicode, bytes)):
return string

if PY2:
method = "encode"
else:
method = "decode"

encodings = ["utf-8", "latin1", "ascii"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle this via str(x, encoding=encoding)? We should add a test case for PyPI repositories that evalueatets this.


for encoding in encodings:
try:
return getattr(string, method)(encoding)
except (UnicodeEncodeError, UnicodeDecodeError):
pass

return getattr(string, method)(encodings[0], errors="ignore")


def list_to_shell_command(cmd):
return " ".join(
'"{}"'.format(token) if " " in token and token[0] not in {"'", '"'} else token
Expand Down