codecov[bot]: # [Codecov](https://codecov.io/gh/pypa/twine/pull/412?src=pr&el=h1) Report
> Merging [#412](https://codecov.io/gh/pypa/twine/pull/412?src=pr&el=desc) into [master](https://codecov.io/gh/pypa/twine/commit/360401bccbe0ae0628c2b1a9304262f5ac033efc?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/pypa/twine/pull/412/graphs/tree.svg?width=650&token=NrvN4iFbj6&height=150&src=pr)](https://codecov.io/gh/pypa/twine/pull/412?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #412   +/-   ##
=======================================
  Coverage   78.08%   78.08%           
=======================================
  Files          14       14           
  Lines         730      730           
  Branches      104      104           
=======================================
  Hits          570      570           
  Misses        127      127           
  Partials       33       33
```


| [Impacted Files](https://codecov.io/gh/pypa/twine/pull/412?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [twine/commands/check.py](https://codecov.io/gh/pypa/twine/pull/412/diff?src=pr&el=tree#diff-dHdpbmUvY29tbWFuZHMvY2hlY2sucHk=) | `100% <ø> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pypa/twine/pull/412?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pypa/twine/pull/412?src=pr&el=footer). Last update [360401b...520d7ff](https://codecov.io/gh/pypa/twine/pull/412?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

di: Since all this command does right now is check if the description is valid, perhaps it should give a warning if there is no `description` value, rather than silently passing? It seems to me like there should be a difference between "this package has provided an empty description" and "this package has not provided a description". The user probably wants to know if the latter is happening.
merwok: I agree with the warning or error.  For example, I found this bug and PR because twine does not include long_description in generated sdists: https://github.com/takluyver/flit/issues/216
asottile: This is pretty special / broken from the setuptools / wheel side.  Here's some data:

```
Checking distribution long/dist/pkg-0.0.0-py3-none-any.whl: 
*******************************************************************************
description: 'long description\n\n\n'
description_content_type: 'text/markdown'
*******************************************************************************

Checking distribution missing/dist/pkg-0.0.0-py3-none-any.whl: 
*******************************************************************************
description: 'UNKNOWN\n\n\n'
description_content_type: None
*******************************************************************************

Checking distribution missing_long/dist/pkg-0.0.0-py3-none-any.whl: 
*******************************************************************************
description: 'UNKNOWN\n\n\n'
description_content_type: 'text/markdown'
*******************************************************************************

Checking distribution missing_type/dist/pkg-0.0.0-py3-none-any.whl: 
*******************************************************************************
description: 'long description\n\n\n'
description_content_type: None
*******************************************************************************

Checking distribution long/dist/pkg-0.0.0.tar.gz: 
*******************************************************************************
description: 'long description'
description_content_type: 'text/markdown'
*******************************************************************************

Checking distribution missing/dist/pkg-0.0.0.tar.gz: 
*******************************************************************************
description: None
description_content_type: None
*******************************************************************************

Checking distribution missing_long/dist/pkg-0.0.0.tar.gz: 
*******************************************************************************
description: None
description_content_type: 'text/markdown'
*******************************************************************************

Checking distribution missing_type/dist/pkg-0.0.0.tar.gz: 
*******************************************************************************
description: 'long description'
description_content_type: None
*******************************************************************************
```

Things to note here:

- wheel will set the description to `'UNKNOWN\n\n\n'` when it is missing
- wheel seems to always add `\n\n\n` to both the description and content type
- these fields appear to always be present, but are sometimes `None`
diff --git a/twine/commands/check.py b/twine/commands/check.py
index 2037761..f71b2c9 100644
--- a/twine/commands/check.py
+++ b/twine/commands/check.py
@@ -33,7 +33,6 @@ from twine.package import PackageFile
 
 _RENDERERS = {
     None: readme_renderer.rst,  # Default if description_content_type is None
-    "": readme_renderer.rst,  # Default if description_content_type is None
     "text/plain": readme_renderer.txt,
     "text/x-rst": readme_renderer.rst,
     "text/markdown": readme_renderer.markdown,
@@ -85,28 +84,33 @@ def check(dists, output_stream=sys.stdout):
         package = PackageFile.from_filename(filename, comment=None)
 
         metadata = package.metadata_dictionary()
-        content_type, parameters = cgi.parse_header(
-            metadata.get("description_content_type") or ""
-        )
-
-        # Get the appropriate renderer
-        renderer = _RENDERERS.get(content_type, readme_renderer.txt)
-
-        # Actually render the given value
-        rendered = renderer.render(
-            metadata.get("description"), stream=stream, **parameters
-        )
+        description = metadata["description"]
+        description_content_type = metadata["description_content_type"]
 
-        if rendered is None:
-            failure = True
-            output_stream.write("Failed\n")
+        if description_content_type is None:
             output_stream.write(
-                "The project's long_description has invalid markup which will "
-                "not be rendered on PyPI. The following syntax errors were "
-                "detected:\n%s" % stream
+                'warning: `long_description_content_type` missing.  '
+                'defaulting to `text/x-rst`.\n'
             )
-        else:
+            description_content_type = 'text/x-rst'
+
+        content_type, params = cgi.parse_header(description_content_type)
+        renderer = _RENDERERS.get(content_type, _RENDERERS[None])
+
+        if description in {None, 'UNKNOWN\n\n\n'}:
+            output_stream.write('warning: `long_description` missing.\n')
             output_stream.write("Passed\n")
+        else:
+            if renderer.render(description, stream=stream, **params) is None:
+                failure = True
+                output_stream.write("Failed\n")
+                output_stream.write(
+                    "The project's long_description has invalid markup which "
+                    "will not be rendered on PyPI. The following syntax "
+                    "errors were detected:\n%s" % stream
+                )
+            else:
+                output_stream.write("Passed\n")
 
     return failure
 

`twine check` against a distribution with no description fails with `AttributeError`
## Your Environment
```console
$ pip freeze --all
bleach==3.0.0
certifi==2018.8.24
cffi==1.11.5
chardet==3.0.4
cmarkgfm==0.4.2
docutils==0.14
future==0.16.0
idna==2.7
pip==18.1
pkginfo==1.4.2
pycparser==2.19
Pygments==2.2.0
readme-renderer==22.0
requests==2.19.1
requests-toolbelt==0.8.0
setuptools==40.4.3
six==1.11.0
tqdm==4.26.0
twine==1.12.1
urllib3==1.23
webencodings==0.5.1
wheel==0.32.1

$ twine --version
twine version 1.12.1 (pkginfo: 1.4.2, requests: 2.19.1, setuptools: 40.4.3,
requests-toolbelt: 0.8.0, tqdm: 4.26.0)

$ python --version --version
Python 3.6.5 (default, Apr  1 2018, 05:46:30) 
[GCC 7.3.0]

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.1 LTS
Release:	18.04
Codename:	bionic
```

## Steps to Reproduce
If the issue is predictable and consistently reproducible, please list the steps here.

### `setup.py`

```python
from setuptools import setup

setup(name='foo', version='0.0.0')
```

### reproduction

```console
$ python setup.py sdist >& /dev/null
$ twine check dist/*
Checking distribution dist/foo-0.0.0.tar.gz: Traceback (most recent call last):
  File "/tmp/t/venv/bin/twine", line 11, in <module>
    sys.exit(main())
  File "/tmp/t/venv/lib/python3.6/site-packages/twine/__main__.py", line 28, in main
    return dispatch(sys.argv[1:])
  File "/tmp/t/venv/lib/python3.6/site-packages/twine/cli.py", line 75, in dispatch
    return main(args.args)
  File "/tmp/t/venv/lib/python3.6/site-packages/twine/commands/check.py", line 126, in main
    return check(args.dists)
  File "/tmp/t/venv/lib/python3.6/site-packages/twine/commands/check.py", line 97, in check
    metadata.get("description"), stream=stream, **parameters
  File "/tmp/t/venv/lib/python3.6/site-packages/readme_renderer/rst.py", line 95, in render
    parts = publish_parts(raw, writer=writer, settings_overrides=settings)
  File "/tmp/t/venv/lib/python3.6/site-packages/docutils/core.py", line 450, in publish_parts
    enable_exit_status=enable_exit_status)
  File "/tmp/t/venv/lib/python3.6/site-packages/docutils/core.py", line 664, in publish_programmatically
    output = pub.publish(enable_exit_status=enable_exit_status)
  File "/tmp/t/venv/lib/python3.6/site-packages/docutils/core.py", line 217, in publish
    self.settings)
  File "/tmp/t/venv/lib/python3.6/site-packages/docutils/readers/__init__.py", line 71, in read
    self.input = self.source.read()
  File "/tmp/t/venv/lib/python3.6/site-packages/docutils/io.py", line 435, in read
    return self.decode(self.source)
  File "/tmp/t/venv/lib/python3.6/site-packages/docutils/io.py", line 99, in decode
    data_encoding = self.determine_encoding_from_data(data)
  File "/tmp/t/venv/lib/python3.6/site-packages/docutils/io.py", line 142, in determine_encoding_from_data
    if data.startswith(start_bytes):
AttributeError: 'NoneType' object has no attribute 'startswith'
```
diff --git a/tests/test_check.py b/tests/test_check.py
index 58bfbdf..deda340 100644
--- a/tests/test_check.py
+++ b/tests/test_check.py
@@ -58,11 +58,13 @@ def test_check_passing_distribution(monkeypatch):
     renderer = pretend.stub(
         render=pretend.call_recorder(lambda *a, **kw: "valid")
     )
-    package = pretend.stub(metadata_dictionary=lambda: {"description": "blah"})
+    package = pretend.stub(metadata_dictionary=lambda: {
+        "description": "blah", 'description_content_type': 'text/markdown',
+    })
     output_stream = check.StringIO()
     warning_stream = ""
 
-    monkeypatch.setattr(check, "_RENDERERS", {"": renderer})
+    monkeypatch.setattr(check, "_RENDERERS", {None: renderer})
     monkeypatch.setattr(check, "_find_dists", lambda a: ["dist/dist.tar.gz"])
     monkeypatch.setattr(
         check,
@@ -81,15 +83,41 @@ def test_check_passing_distribution(monkeypatch):
     ]
 
 
+def test_check_no_description(monkeypatch, capsys):
+    package = pretend.stub(metadata_dictionary=lambda: {
+        'description': None, 'description_content_type': None,
+    })
+
+    monkeypatch.setattr(check, "_find_dists", lambda a: ["dist/dist.tar.gz"])
+    monkeypatch.setattr(
+        check,
+        "PackageFile",
+        pretend.stub(from_filename=lambda *a, **kw: package),
+    )
+
+    # used to crash with `AttributeError`
+    output_stream = check.StringIO()
+    check.check("dist/*", output_stream=output_stream)
+    assert output_stream.getvalue() == (
+        'Checking distribution dist/dist.tar.gz: '
+        'warning: `long_description_content_type` missing.  '
+        'defaulting to `text/x-rst`.\n'
+        'warning: `long_description` missing.\n'
+        'Passed\n'
+    )
+
+
 def test_check_failing_distribution(monkeypatch):
     renderer = pretend.stub(
         render=pretend.call_recorder(lambda *a, **kw: None)
     )
-    package = pretend.stub(metadata_dictionary=lambda: {"description": "blah"})
+    package = pretend.stub(metadata_dictionary=lambda: {
+        "description": "blah", "description_content_type": 'text/markdown',
+    })
     output_stream = check.StringIO()
     warning_stream = "WARNING"
 
-    monkeypatch.setattr(check, "_RENDERERS", {"": renderer})
+    monkeypatch.setattr(check, "_RENDERERS", {None: renderer})
     monkeypatch.setattr(check, "_find_dists", lambda a: ["dist/dist.tar.gz"])
     monkeypatch.setattr(
         check,

pip install -e .[keyring]
parse_log_pytest
requirements.txt
pytest coverage pretend readme_renderer doc8 tox tox-pipenv
apt-get update apt-get install -y gcc
3.6
requirements/base.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
bleach==4.1.0
certifi==2021.5.30
cffi==1.15.1
charset-normalizer==2.0.12
coverage==6.2
cryptography==40.0.2
distlib==0.3.9
doc8==0.11.2
docutils==0.18.1
filelock==3.4.1
idna==3.10
importlib-metadata==4.8.3
importlib-resources==5.4.0
iniconfig==1.1.1
jeepney==0.7.1
keyring==23.4.1
packaging==21.3
pbr==6.1.1
pipenv==2022.4.8
pkginfo==1.10.0
platformdirs==2.4.0
pluggy==1.0.0
pretend==1.0.9
py==1.11.0
pycparser==2.21
Pygments==2.14.0
pyparsing==3.1.4
pytest==7.0.1
readme-renderer==34.0
requests==2.27.1
requests-toolbelt==1.0.0
restructuredtext-lint==1.4.0
SecretStorage==3.3.3
six==1.17.0
stevedore==3.5.2
toml==0.10.2
tomli==1.2.3
tox==3.28.0
tox-pipenv==1.10.1
tqdm==4.64.1
-e git+https://github.com/pypa/twine.git@360401bccbe0ae0628c2b1a9304262f5ac033efc#egg=twine
typing_extensions==4.1.1
urllib3==1.26.20
virtualenv==20.17.1
virtualenv-clone==0.5.7
webencodings==0.5.1
zipp==3.6.0

name: twine
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - bleach==4.1.0
      - cffi==1.15.1
      - charset-normalizer==2.0.12
      - coverage==6.2
      - cryptography==40.0.2
      - distlib==0.3.9
      - doc8==0.11.2
      - docutils==0.18.1
      - filelock==3.4.1
      - idna==3.10
      - importlib-metadata==4.8.3
      - importlib-resources==5.4.0
      - iniconfig==1.1.1
      - jeepney==0.7.1
      - keyring==23.4.1
      - packaging==21.3
      - pbr==6.1.1
      - pipenv==2022.4.8
      - pkginfo==1.10.0
      - platformdirs==2.4.0
      - pluggy==1.0.0
      - pretend==1.0.9
      - py==1.11.0
      - pycparser==2.21
      - pygments==2.14.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - readme-renderer==34.0
      - requests==2.27.1
      - requests-toolbelt==1.0.0
      - restructuredtext-lint==1.4.0
      - secretstorage==3.3.3
      - six==1.17.0
      - stevedore==3.5.2
      - toml==0.10.2
      - tomli==1.2.3
      - tox==3.28.0
      - tox-pipenv==1.10.1
      - tqdm==4.64.1
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - virtualenv==20.17.1
      - virtualenv-clone==0.5.7
      - webencodings==0.5.1
      - zipp==3.6.0
prefix: /opt/conda/envs/twine

tests/test_check.py::test_check_passing_distribution tests/test_check.py::test_check_no_description tests/test_check.py::test_check_failing_distribution
tests/test_check.py::test_warningstream_write_match tests/test_check.py::test_warningstream_write_nomatch tests/test_check.py::test_warningstream_str tests/test_check.py::test_check_no_distributions tests/test_check.py::test_main
twine/commands/check.py
twine/commands/check.py