# Buggy code
def upload_distribution():
    tools.assert_can_release()

    subprocess.check_call(
        [
            sys.executable,
            "-m",
            "twine",
            "upload",
            "--skip-existing",
            "--config-file",
            tools.PYPIRC,
            os.path.join(DIST, "*"),
        ]
    )

    # Construct plain-text + markdown version of this changelog entry,
    # with link to canonical source.
    build_docs(builder="text")
    textfile = os.path.join(HYPOTHESIS_PYTHON, "docs", "_build", "text", "changes.txt")
    with open(textfile) as f:
        lines = f.readlines()
    entries = [i for i, l in enumerate(lines) if CHANGELOG_HEADER.match(l)]
    changelog_body = "".join(lines[entries[0] + 2 : entries[1]]).strip() + (
        "\n\n*[The canonical version of these notes (with links) is on readthedocs.]"
        "(https://hypothesis.readthedocs.io/en/latest/changes.html#v%s)*"
        % (current_version().replace(".", "-"),)
    )

    # Create a GitHub release, to trigger Zenodo DOI minting.  See
    # https://developer.github.com/v3/repos/releases/#create-a-release
    requests.post(
        "https://api.github.com/repos/HypothesisWorks/hypothesis/releases",
        json={
            "tag_name": tag_name(),
            "name": "Hypothesis for Python - version " + current_version(),
            "body": changelog_body,
        },
        timeout=120,  # seconds
        # Scoped personal access token, stored in Travis environ variable
        auth=("Zac-HD", os.environ["Zac_release_token"]),
    ).raise_for_status()

    # Post the release notes to Tidelift too - see https://tidelift.com/docs/api
    requests.post(
        "https://api.tidelift.com/external-api/lifting/pypi/hypothesis/release-notes/"
        + current_version(),
        json={"body": changelog_body},
        headers={"Authorization": "Bearer {}".format(os.environ["TIDELIFT_API_TOKEN"])},
        timeout=120,  # seconds
    ).raise_for_status()


# Traceback (AttributeError)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "...\hypothesis\strategies\_internal\strategies.py", line 314, in example
example_generating_inner_function()
File "...\hypothesis\strategies\_internal\strategies.py", line 302, in example_generating_inner_function
@settings(
File "...\hypothesis\core.py", line 1023, in wrapped_test
processed_args = process_arguments_to_given(
File "...\hypothesis\core.py", line 441, in process_arguments_to_given
search_strategy.validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 377, in validate
self.do_validate()
File "...\hypothesis\strategies\_internal\collections.py", line 39, in do_validate
s.validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 377, in validate
self.do_validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 638, in do_validate
self.mapped_strategy.validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 377, in validate
self.do_validate()
File "...\hypothesis\strategies\_internal\lazy.py", line 118, in do_validate
w.validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 377, in validate
self.do_validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 638, in do_validate
self.mapped_strategy.validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 377, in validate
self.do_validate()
File "...\hypothesis\strategies\_internal\collections.py", line 39, in do_validate
s.validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 377, in validate
self.do_validate()
File "...\hypothesis\strategies\_internal\strategies.py", line 595, in do_validate
for e in self.element_strategies:
File "...\hypothesis\strategies\_internal\strategies.py", line 570, in element_strategies
if not arg.is_empty:
File "...\hypothesis\strategies\_internal\strategies.py", line 125, in accept
recur(self)
File "...\hypothesis\strategies\_internal\strategies.py", line 121, in recur
mapping[strat] = getattr(strat, calculation)(recur)
File "...\hypothesis\strategies\_internal\lazy.py", line 86, in calc_is_empty
return recur(self.wrapped_strategy)
File "...\hypothesis\strategies\_internal\strategies.py", line 121, in recur
mapping[strat] = getattr(strat, calculation)(recur)
File "...\hypothesis\strategies\_internal\deferred.py", line 80, in calc_is_empty
return recur(self.wrapped_strategy)
File "...\hypothesis\strategies\_internal\deferred.py", line 55, in wrapped_strategy
del self.__definition
AttributeError: _DeferredStrategy__definition

# Fixed code
def upload_distribution():
    tools.assert_can_release()

    subprocess.check_call(
        [
            sys.executable,
            "-m",
            "twine",
            "upload",
            "--skip-existing",
            "--username=__token__",
            os.path.join(DIST, "*"),
        ]
    )

    # Construct plain-text + markdown version of this changelog entry,
    # with link to canonical source.
    build_docs(builder="text")
    textfile = os.path.join(HYPOTHESIS_PYTHON, "docs", "_build", "text", "changes.txt")
    with open(textfile) as f:
        lines = f.readlines()
    entries = [i for i, l in enumerate(lines) if CHANGELOG_HEADER.match(l)]
    changelog_body = "".join(lines[entries[0] + 2 : entries[1]]).strip() + (
        "\n\n*[The canonical version of these notes (with links) is on readthedocs.]"
        "(https://hypothesis.readthedocs.io/en/latest/changes.html#v%s)*"
        % (current_version().replace(".", "-"),)
    )

    # Create a GitHub release, to trigger Zenodo DOI minting.  See
    # https://developer.github.com/v3/repos/releases/#create-a-release
    requests.post(
        "https://api.github.com/repos/HypothesisWorks/hypothesis/releases",
        json={
            "tag_name": tag_name(),
            "name": "Hypothesis for Python - version " + current_version(),
            "body": changelog_body,
        },
        timeout=120,  # seconds
    ).raise_for_status()