Skip to content

Commit

Permalink
handle ast.Str deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby committed Jun 20, 2023
1 parent e61de43 commit 46a6aca
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/poetry/utils/setup_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ def _find_install_requires(self, call: ast.Call, body: list[ast.stmt]) -> list[s

if isinstance(value, ast.List):
for el in value.elts:
if isinstance(el, ast.Str):
install_requires.append(el.s)
if isinstance(el, ast.Constant) and isinstance(el.value, str):
install_requires.append(el.value)
elif isinstance(value, ast.Name):
variable = self._find_variable_in_body(body, value.id)

if variable is not None and isinstance(variable, ast.List):
for el in variable.elts:
if isinstance(el, ast.Str):
install_requires.append(el.s)
if isinstance(el, ast.Constant) and isinstance(el.value, str):
install_requires.append(el.value)

return install_requires

Expand Down Expand Up @@ -258,15 +258,17 @@ def _find_extras_require(
if isinstance(value, ast.Dict):
val: ast.expr | None
for key, val in zip(value.keys, value.values):
if not isinstance(key, ast.Str):
if not isinstance(key, ast.Constant) or not isinstance(key.value, str):
continue

if isinstance(val, ast.Name):
val = self._find_variable_in_body(body, val.id)

if isinstance(val, ast.List):
extras_require[key.s] = [
e.s for e in val.elts if isinstance(e, ast.Str)
extras_require[key.value] = [
e.value
for e in val.elts
if isinstance(e, ast.Constant) and isinstance(e.value, str)
]
elif isinstance(value, ast.Name):
variable = self._find_variable_in_body(body, value.id)
Expand All @@ -275,15 +277,17 @@ def _find_extras_require(
return extras_require

for key, val in zip(variable.keys, variable.values):
if not isinstance(key, ast.Str):
if not isinstance(key, ast.Constant) or not isinstance(key.value, str):
continue

if isinstance(val, ast.Name):
val = self._find_variable_in_body(body, val.id)

if isinstance(val, ast.List):
extras_require[key.s] = [
e.s for e in val.elts if isinstance(e, ast.Str)
extras_require[key.value] = [
e.value
for e in val.elts
if isinstance(e, ast.Constant) and isinstance(e.value, str)
]

return extras_require
Expand Down Expand Up @@ -317,13 +321,17 @@ def _find_single_string(
if value is None:
return None

if isinstance(value, ast.Str):
return value.s
if isinstance(value, ast.Constant) and isinstance(value.value, str):
return value.value
elif isinstance(value, ast.Name):
variable = self._find_variable_in_body(body, value.id)

if variable is not None and isinstance(variable, ast.Str):
return variable.s
if (
variable is not None
and isinstance(variable, ast.Constant)
and isinstance(variable.value, str)
):
return variable.value

return None

Expand Down Expand Up @@ -359,7 +367,11 @@ def _find_variable_in_body(

def _find_in_dict(self, dict_: ast.Dict, name: str) -> ast.expr | None:
for key, val in zip(dict_.keys, dict_.values):
if isinstance(key, ast.Str) and key.s == name:
if (
isinstance(key, ast.Constant)
and isinstance(key.value, str)
and key.value == name
):
return val

return None

0 comments on commit 46a6aca

Please sign in to comment.