Repository: python-poetry/poetry

Issue:
Could not parse version constraint: <empty>
<!--
  Hi there! Thank you for discovering and submitting an issue.

  Before you submit this; let's make sure of a few things.
  Please make sure the following boxes are ticked if they are correct.
  If not, please try and fulfill these first.
-->

<!-- Checked checkbox should look like this: [x] -->
- [x] I am on the [latest](https://github.com/python-poetry/poetry/releases/latest) Poetry version.
- [x] I have searched the [issues](https://github.com/python-poetry/poetry/issues) of this repo and believe that this is not a duplicate.
- [x] If an exception occurs when executing a command, I executed it again in debug mode (`-vvv` option).

<!--
  Once those are done, if you're able to fill in the following list with your information,
  it'd be very helpful to whoever handles the issue.
-->

- **OS version and name**: macOS 10.15.2
- **Poetry version**: 1.0.0(master branch in fact)
- **Link of a [Gist](https://gist.github.com/) with the contents of your pyproject.toml file**: <!-- Gist Link Here -->

## Issue
<!-- Now feel free to write your issue, but please be descriptive! Thanks again 🙌 ❤️ -->

The following lines:
https://github.com/python-poetry/poetry/blob/06cdc7731b0223ab98642137b468d37d18771f6c/poetry/puzzle/provider.py#L676-L680

When the package python constraint(e.g. We want `flake8` for python `>=3.6` only, it doesn't overlap with dep python constraint(e.g. `configparser` is only needed for python `<3.2`), it means `configparser` is not required at all and shouldn't be listed in the lock result. However, in this case `poetry` will throw a `Could not parse version constraint: <empty>` error because the intersection version is `<empty>`.

Error detail:
```
Traceback (most recent call last):
  File "/Users/fming/.virtualenvs/poetry-ZHUPScpV-py3.7/lib/python3.7/site-packages/clikit/console_application.py", line 131, in run
    status_code = command.handle(parsed_args, io)
  File "/Users/fming/.virtualenvs/poetry-ZHUPScpV-py3.7/lib/python3.7/site-packages/clikit/api/command/command.py", line 120, in handle
    status_code = self._do_handle(args, io)
  File "/Users/fming/.virtualenvs/poetry-ZHUPScpV-py3.7/lib/python3.7/site-packages/clikit/api/command/command.py", line 171, in _do_handle
    return getattr(handler, handler_method)(args, io, self)
  File "/Users/fming/.virtualenvs/poetry-ZHUPScpV-py3.7/lib/python3.7/site-packages/cleo/commands/command.py", line 92, in wrap_handle
    return self.handle()
  File "/Users/fming/wkspace/github/poetry/poetry/console/commands/add.py", line 149, in handle
    status = installer.run()
  File "/Users/fming/wkspace/github/poetry/poetry/installation/installer.py", line 74, in run
    self._do_install(local_repo)
  File "/Users/fming/wkspace/github/poetry/poetry/installation/installer.py", line 161, in _do_install
    ops = solver.solve(use_latest=self._whitelist)
  File "/Users/fming/wkspace/github/poetry/poetry/puzzle/solver.py", line 36, in solve
    packages, depths = self._solve(use_latest=use_latest)
  File "/Users/fming/wkspace/github/poetry/poetry/puzzle/solver.py", line 181, in _solve
    self._package, self._provider, locked=locked, use_latest=use_latest
  File "/Users/fming/wkspace/github/poetry/poetry/mixology/__init__.py", line 7, in resolve_version
    return solver.solve()
  File "/Users/fming/wkspace/github/poetry/poetry/mixology/version_solver.py", line 80, in solve
    next = self._choose_package_version()
  File "/Users/fming/wkspace/github/poetry/poetry/mixology/version_solver.py", line 378, in _choose_package_version
    version = self._provider.complete_package(version)
  File "/Users/fming/wkspace/github/poetry/poetry/puzzle/provider.py", line 678, in complete_package
    package.dependency.python_constraint
  File "/Users/fming/wkspace/github/poetry/poetry/packages/dependency.py", line 118, in transitive_python_versions
    self._transitive_python_constraint = parse_constraint(value)
  File "/Users/fming/wkspace/github/poetry/poetry/semver/__init__.py", line 31, in parse_constraint
    constraint_objects.append(parse_single_constraint(and_constraints[0]))
  File "/Users/fming/wkspace/github/poetry/poetry/semver/__init__.py", line 164, in parse_single_constraint
    raise ValueError('Could not parse version constraint: {}'.format(constraint))
```

### Steps to replicate

```bash
$ poetry add -D -vvv --python ">=3.6" pytest
```

## Possible related:

#1484 



Discussion:

Resolving patch:
diff --git a/poetry/puzzle/provider.py b/poetry/puzzle/provider.py
--- a/poetry/puzzle/provider.py
+++ b/poetry/puzzle/provider.py
@@ -671,13 +671,16 @@ def complete_package(
             raise CompatibilityError(*python_constraints)
 
         # Modifying dependencies as needed
+        clean_dependencies = []
         for dep in dependencies:
             if not package.dependency.python_constraint.is_any():
-                dep.transitive_python_versions = str(
-                    dep.python_constraint.intersect(
-                        package.dependency.python_constraint
-                    )
+                python_constraint_intersection = dep.python_constraint.intersect(
+                    package.dependency.python_constraint
                 )
+                if python_constraint_intersection.is_empty():
+                    # This depencency is not needed under current python constraint.
+                    continue
+                dep.transitive_python_versions = str(python_constraint_intersection)
 
             if (package.dependency.is_directory() or package.dependency.is_file()) and (
                 dep.is_directory() or dep.is_file()
@@ -691,8 +694,9 @@ def complete_package(
 
                 # TODO: Improve the way we set the correct relative path for dependencies
                 dep._path = relative
+            clean_dependencies.append(dep)
 
-        package.requires = dependencies
+        package.requires = clean_dependencies
 
         return package
 


Test patch:
diff --git a/tests/puzzle/test_solver.py b/tests/puzzle/test_solver.py
--- a/tests/puzzle/test_solver.py
+++ b/tests/puzzle/test_solver.py
@@ -1887,3 +1887,19 @@ def test_solver_does_not_fail_with_locked_git_and_non_git_dependencies(
             {"job": "install", "package": git_package, "skipped": True},
         ],
     )
+
+
+def test_ignore_python_constraint_no_overlap_dependencies(solver, repo, package):
+    pytest = get_package("demo", "1.0.0")
+    pytest.add_dependency("configparser", {"version": "^1.2.3", "python": "<3.2"})
+
+    package.add_dependency("demo", {"version": "^1.0.0", "python": "^3.6"})
+
+    repo.add_package(pytest)
+    repo.add_package(get_package("configparser", "1.2.3"))
+
+    ops = solver.solve()
+
+    check_solver_result(
+        ops, [{"job": "install", "package": pytest}],
+    )