Repository: python-poetry/poetry

Issue:
`~=` version constraints (PEP 440) do not correctly set the lower version
<!--
  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/sdispater/poetry/releases/latest) Poetry version.
- [x] I have searched the [issues](https://github.com/sdispater/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**: Windows 10
- **Poetry version**: 0.12.16
- **Link of a [Gist](https://gist.github.com/) with the contents of your pyproject.toml file**: N/A

## Issue
<!-- Now feel free to write your issue, but please be descriptive! Thanks again 🙌 ❤️ -->

Found this while fixing handling of pre-release (#1150)

PEP 440 says
- `~=V.N` maps to `>= V.N, == V.*`

Examples
```
~= 2.2
>= 2.2, == 2.*

~= 1.4.5
>= 1.4.5, == 1.4.*

~= 2.2.0
>= 2.2.0, == 2.2.*

~= 1.4.5.0
>= 1.4.5.0, == 1.4.5.*
```

but looking at the tests `~=3.5.3` maps to `>=3.5.0, < 3.6` when it should map to `>=3.5.3, <3.6`. The trailing `3` should be setting the floor for the version


Discussion:
Also having issues with this. Example pyproject.toml:

```toml
[tool.poetry]
name = "cirq-test"
version = "0.1.0"
description = ""

[tool.poetry.dependencies]
python = "^3.7"
cirq = "0.5"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
```

Package cirq requires ```sortedcontainers~=2.0``` (see [requirements.txt](https://github.com/quantumlib/Cirq/blob/master/requirements.txt))

Running ```poetry install``` leads to:

```
  - Installing sortedcontainers (1.5.10)
```
When clearly the PEP 440 spec specifies that ```~=2.0``` should resolve to ```>=2.0,==2.*``` which would exclude ```1.5.10```. FYI the latest stable version of sortedcontainers is currently [2.1.0](https://pypi.org/project/sortedcontainers/#history).

@stevegore Your case is different and is not a bug. `cirq` declares this dependency `sortedcontainers (~=1.5)` as you can see here: https://pypi.org/pypi/cirq/json

Resolving patch:
diff --git a/poetry/semver/__init__.py b/poetry/semver/__init__.py
--- a/poetry/semver/__init__.py
+++ b/poetry/semver/__init__.py
@@ -79,7 +79,7 @@ def parse_single_constraint(constraint):  # type: (str) -> VersionConstraint
             low = version
             high = version.stable.next_major
         else:
-            low = Version(version.major, version.minor, 0)
+            low = Version(version.major, version.minor, version.patch)
             high = version.stable.next_minor
 
         return VersionRange(


Test patch:
diff --git a/tests/semver/test_main.py b/tests/semver/test_main.py
--- a/tests/semver/test_main.py
+++ b/tests/semver/test_main.py
@@ -67,7 +67,7 @@ def test_parse_constraint_wildcard(input, constraint):
         ("~0.3", VersionRange(Version(0, 3, 0), Version(0, 4, 0), True)),
         ("~3.5", VersionRange(Version(3, 5, 0), Version(3, 6, 0), True)),
         ("~=3.5", VersionRange(Version(3, 5, 0), Version(4, 0, 0), True)),  # PEP 440
-        ("~=3.5.3", VersionRange(Version(3, 5, 0), Version(3, 6, 0), True)),  # PEP 440
+        ("~=3.5.3", VersionRange(Version(3, 5, 3), Version(3, 6, 0), True)),  # PEP 440
     ],
 )
 def test_parse_constraint_tilde(input, constraint):