D100 missing docstring in public module как исправить

I installed atom for python programming
and also installed Linter and flake8
packages but everything I write in text editor I get this warning :

D100 — Missing docstring in public module

I already tried

 pip uninstall flake8-docstrings
 pip install Flake8-pep257

How can I fix this warning ?

NAND's user avatar

NAND

6618 silver badges22 bronze badges

asked Sep 13, 2017 at 8:28

Sami Soheili's user avatar

Its nothing but a comment like this on the top of your program. According to Python Documentation it should be there before every function and program. Here is a simple docstring code

“””Return the pathname of the KOS root directory.”””

answered May 19, 2018 at 7:16

Rakesh Kumar's user avatar

You can configure linter-flake8 like any Atom package by editing the settings in Atom -> Preferences -> Packages -> linter-flake8.

Use “ignore error codes” for any errors that you don’t want to see.

answered Sep 13, 2017 at 8:34

mdegis's user avatar

mdegismdegis

2,0782 gold badges21 silver badges39 bronze badges

0

install “linter-ui-default dependencies” from the atom packages store..
It helped me.. for the first time it could not be installed. I restarted Atom and it asked me to install this package. clicking on yes it was installed successfully. And now I am not getting any error.

answered Feb 27, 2018 at 10:49

Usman Gill's user avatar

Usman GillUsman Gill

314 silver badges12 bronze badges

1. Summary

In valid py file I get warning D100: Missing docstring in public module.

2. Settings

My pelicanconf.py:

#!/usr/bin/env python
# -*- coding: utf-8 -*- #

import logging
""" logging pelican module.

For disabling warnings:
http://docs.getpelican.com/en/stable/settings.html#logging
"""
import sys
"""sys module.

For download plugins from “plugins” folder.
"""

# That Pelican see plugins from this folder
sys.path.append('plugins')

# ****************************************************************************
# *                                  General                                 *
# ****************************************************************************

AUTHOR = 'Саша Черных'
SITENAME = 'Поиск Кристиниты'
SITEURL = 'http://kristinita.ru'

TIMEZONE = 'Europe/Moscow'
DEFAULT_LANG = 'en'

# ****************************************************************************
# *                                   Feed                                   *
# ****************************************************************************

# Feed generation, perhaps, not desired when developing
FEED_ALL_ATOM = 'feeds/all.atom.xml'
CATEGORY_FEED_ATOM = 'feeds/%s.atom.xml'
TRANSLATION_FEED_ATOM = None
AUTHOR_FEED_ATOM = None
AUTHOR_FEED_RSS = None

# Blogroll
# LINKS = (('Pelican', 'http://getpelican.com/'),
#          ('Python.org', 'http://python.org/'),
#          ('Jinja2', 'http://jinja.pocoo.org/'),
#          ('You can edit those links in your config file', '#'),)

# Social widget
# SOCIAL = (('You can add links in your config file', '#'),
#           ('Another social link', '#'),)


# ****************************************************************************
# *                                 Markdown                                 *
# ****************************************************************************

# Include Markdown extensions
# http://docs.getpelican.com/en/stable/settings.html?highlight=MARKDOWN#basic-settings
# https://pythonhosted.org/Markdown/extensions/#third-party-extensions
MARKDOWN = {
    'extension_configs': {
        # Fenced code blocks
        # https://pythonhosted.org/Markdown/extensions/fenced_code_blocks.html
        'markdown.extensions.fenced_code': {},
    },
    'output_format': 'html5',
}

# ****************************************************************************
# *                                Generation                                *
# ****************************************************************************

# Delete old site before building
DELETE_OUTPUT_DIRECTORY = True

# Do not touch in generation process
OUTPUT_RETENTION = [".git"]

LOAD_CONTENT_CACHE = False

# Uncomment following line if you want document-relative URLs when developing
RELATIVE_URLS = True

# Original format without rendering. If true, md rendering to md,
# not md → html
OUTPUT_SOURCES = False

# ****************************************************************************
# *                                  Plugins                                 *
# ****************************************************************************

PLUGIN_PATHS = ['pelican-plugins']
PLUGINS = ['pagefixer', 'pelican_javascript', 'sitemap', 'section_number']

# Sitemap
# https://github.com/getpelican/pelican-plugins/tree/master/sitemap

SITEMAP = {
    'format': 'xml',
    'priorities': {
        'articles': 0,
        'indexes': 0.5,
        'pages': 1
    },
    'changefreqs': {
        'articles': 'never',
        'indexes': 'weekly',
        'pages': 'always'
    }
}

# Section number
# https://github.com/getpelican/pelican-plugins/tree/master/section_number

SECTION_NUMBER_MAX = 5

# Replacer
# https://github.com/narusemotoki/replacer.git

REPLACES = (
    (u'css\/personal', u'..\/css\/personal'),
)

# ****************************************************************************
# *                                   Paths                                  *
# ****************************************************************************

# Path for site content

PATH = 'content'

# Path for pages
# Don't set “PAGE_PATHS = ['']”! See
# https://github.com/getpelican/pelican/issues/2123

PAGE_PATHS = ['Gingerinas', 'Giologica', 'Life-hacks', 'Sasha-Black',
              'Smert-svobode', 'Sublime-Text']

# Path for articles
# [Hack] That exclude articles, include non-exicting folder.
# «ARTICLE_PATHS = None» — critical error, integer parameter

ARTICLE_PATHS = ['None']

# Non-modified files and folders
# [Hack] The register matters. 404.md & 404.html don't work.

STATIC_PATHS = ['']

# That filename = Slug, not necessary to write slug manually for each article

SLUGIFY_SOURCE = 'basename'

# Extra path metadata
# http://manos.im/blog/static-site-pelican-grunt-travis-github-pages/

PAGE_URL = '{slug}.html'
PAGE_SAVE_AS = PAGE_URL
CATEGORY_URL = 'category/{slug}.html'
CATEGORY_SAVE_AS = CATEGORY_URL
TAG_URL = 'tag/{slug}.html'
TAG_SAVE_AS = TAG_URL
TAGS_SAVE_AS = 'tag/alltags.html'

# ****************************************************************************
# *                                   Other                                  *
# ****************************************************************************

# Theme

THEME = 'themes/sashapelican'

# Pagination — division of articles

DEFAULT_PAGINATION = False

TYPOGRIFY = True

# Disable logging of empty alt attribute, needs “import logging” module

LOG_FILTER = [(logging.WARN, 'Empty alt attribute for image %s in %s')]

3. Steps to reproduce

I reproduce the problem in a version of Sublime Text without plugins and user settings.

I install Flake8Lint → I restart Sublime Text → I open pelicanconf.py.

4. Expected behavior

If I check my file in a terminal:

D:Kristinita>flake8 -v pelicanconf.py
flake8.plugins.manager    MainProcess    226 INFO     Loading entry-points for "flake8.extension".

flake8.plugins.manager    MainProcess    288 INFO     Loading entry-points for "flake8.listen".
flake8.plugins.manager    MainProcess    288 INFO     Loading entry-points for "flake8.report".
flake8.plugins.manager    MainProcess    290 INFO     Loading plugin "C90" from entry-point.
flake8.plugins.manager    MainProcess    291 INFO     Loading plugin "F" from entry-point.
flake8.plugins.manager    MainProcess    314 INFO     Loading plugin "pycodestyle.blank_lines" from entry-point.
flake8.plugins.manager    MainProcess    320 INFO     Loading plugin "pycodestyle.break_around_binary_operator" from entry-point.
flake8.plugins.manager    MainProcess    320 INFO     Loading plugin "pycodestyle.comparison_negative" from entry-point.
flake8.plugins.manager    MainProcess    320 INFO     Loading plugin "pycodestyle.comparison_to_singleton" from entry-point.
flake8.plugins.manager    MainProcess    320 INFO     Loading plugin "pycodestyle.comparison_type" from entry-point.
flake8.plugins.manager    MainProcess    321 INFO     Loading plugin "pycodestyle.compound_statements" from entry-point.
flake8.plugins.manager    MainProcess    321 INFO     Loading plugin "pycodestyle.continued_indentation" from entry-point.
flake8.plugins.manager    MainProcess    321 INFO     Loading plugin "pycodestyle.explicit_line_join" from entry-point.
flake8.plugins.manager    MainProcess    321 INFO     Loading plugin "pycodestyle.extraneous_whitespace" from entry-point.
flake8.plugins.manager    MainProcess    321 INFO     Loading plugin "pycodestyle.imports_on_separate_lines" from entry-point.
flake8.plugins.manager    MainProcess    322 INFO     Loading plugin "pycodestyle.indentation" from entry-point.
flake8.plugins.manager    MainProcess    324 INFO     Loading plugin "pycodestyle.maximum_line_length" from entry-point.
flake8.plugins.manager    MainProcess    325 INFO     Loading plugin "pycodestyle.missing_whitespace" from entry-point.
flake8.plugins.manager    MainProcess    327 INFO     Loading plugin "pycodestyle.missing_whitespace_after_import_keyword" from entry-point.
flake8.plugins.manager    MainProcess    330 INFO     Loading plugin "pycodestyle.missing_whitespace_around_operator" from entry-point.
flake8.plugins.manager    MainProcess    331 INFO     Loading plugin "pycodestyle.module_imports_on_top_of_file" from entry-point.
flake8.plugins.manager    MainProcess    331 INFO     Loading plugin "pycodestyle.python_3000_backticks" from entry-point.
flake8.plugins.manager    MainProcess    331 INFO     Loading plugin "pycodestyle.python_3000_has_key" from entry-point.
flake8.plugins.manager    MainProcess    331 INFO     Loading plugin "pycodestyle.python_3000_not_equal" from entry-point.
flake8.plugins.manager    MainProcess    331 INFO     Loading plugin "pycodestyle.python_3000_raise_comma" from entry-point.
flake8.plugins.manager    MainProcess    333 INFO     Loading plugin "pycodestyle.tabs_obsolete" from entry-point.
flake8.plugins.manager    MainProcess    333 INFO     Loading plugin "pycodestyle.tabs_or_spaces" from entry-point.
flake8.plugins.manager    MainProcess    333 INFO     Loading plugin "pycodestyle.trailing_blank_lines" from entry-point.
flake8.plugins.manager    MainProcess    333 INFO     Loading plugin "pycodestyle.trailing_whitespace" from entry-point.
flake8.plugins.manager    MainProcess    333 INFO     Loading plugin "pycodestyle.whitespace_around_comma" from entry-point.
flake8.plugins.manager    MainProcess    333 INFO     Loading plugin "pycodestyle.whitespace_around_keywords" from entry-point.
flake8.plugins.manager    MainProcess    334 INFO     Loading plugin "pycodestyle.whitespace_around_named_parameter_equals" from entry-point.
flake8.plugins.manager    MainProcess    334 INFO     Loading plugin "pycodestyle.whitespace_around_operator" from entry-point.
flake8.plugins.manager    MainProcess    334 INFO     Loading plugin "pycodestyle.whitespace_before_comment" from entry-point.
flake8.plugins.manager    MainProcess    334 INFO     Loading plugin "pycodestyle.whitespace_before_parameters" from entry-point.
flake8.plugins.manager    MainProcess    334 INFO     Loading plugin "default" from entry-point.
flake8.plugins.manager    MainProcess    338 INFO     Loading plugin "pylint" from entry-point.
flake8.plugins.manager    MainProcess    343 INFO     Loading plugin "quiet-filename" from entry-point.
flake8.plugins.manager    MainProcess    345 INFO     Loading plugin "quiet-nothing" from entry-point.
flake8.checker            MainProcess    349 WARNING  The --jobs option is not available on Windows due to a bug (https://bugs.python.org/issue27649) in Python 2.7.11+ and 3.3+. We have detected that you are running an unsupported version of Python on Windows. Ignoring --jobs arguments.
flake8.checker            MainProcess    349 INFO     Making checkers
flake8.checker            MainProcess    356 INFO     Checking 1 files
flake8.main.application   MainProcess    400 INFO     Finished running
flake8.main.application   MainProcess    401 INFO     Reporting errors
flake8.main.application   MainProcess    401 INFO     Found a total of 0 violations and reported 0

Also, I don’t get a warning, if I use SublimeLinter-flake8 package.

5. Actual behavior

Actual

6. Environment

Operating system and version:
Windows 10 Enterprise LTSB 64-bit EN
Sublime Text:
Build 3126
Python:
3.6.1
Flake8:
3.3.0 (mccabe: 0.6.1, pycodestyle: 2.3.1, pyflakes: 1.5.0) CPython 3.6.1 on Windows

Thanks.

On Python ≥ 3.5, use pathlib.Path.mkdir:

from pathlib import Path
Path("/my/directory").mkdir(parents=True, exist_ok=True)

For older versions of Python, I see two answers with good qualities, each with a small flaw, so I will give my take on it:

Try os.path.exists, and consider os.makedirs for the creation.

import os
if not os.path.exists(directory):
    os.makedirs(directory)

As noted in comments and elsewhere, there’s a race condition – if the directory is created between the os.path.exists and the os.makedirs calls, the os.makedirs will fail with an OSError. Unfortunately, blanket-catching OSError and continuing is not foolproof, as it will ignore a failure to create the directory due to other factors, such as insufficient permissions, full disk, etc.

One option would be to trap the OSError and examine the embedded error code (see Is there a cross-platform way of getting information from Python’s OSError):

import os, errno

try:
    os.makedirs(directory)
except OSError as e:
    if e.errno != errno.EEXIST:
        raise

Alternatively, there could be a second os.path.exists, but suppose another created the directory after the first check, then removed it before the second one – we could still be fooled.

Depending on the application, the danger of concurrent operations may be more or less than the danger posed by other factors such as file permissions. The developer would have to know more about the particular application being developed and its expected environment before choosing an implementation.

Modern versions of Python improve this code quite a bit, both by exposing FileExistsError (in 3.3+)…

try:
    os.makedirs("path/to/directory")
except FileExistsError:
    # directory already exists
    pass

…and by allowing a keyword argument to os.makedirs called exist_ok (in 3.2+).

os.makedirs("path/to/directory", exist_ok=True)  # succeeds even if directory exists.

You create a new key/value pair on a dictionary by assigning a value to that key

d = {'key': 'value'}
print(d)  # {'key': 'value'}

d['mynewkey'] = 'mynewvalue'

print(d)  # {'key': 'value', 'mynewkey': 'mynewvalue'}

If the key doesn’t exist, it’s added and points to that value. If it exists, the current value it points to is overwritten.

utkonos opened this issue a year ago · comments

I am using pydocstyle 6.1.1 which is supposed to be aware of __init__.py and only emit D107. However I am getting the following error reported in these files:

pydocstyle: warning
D100 - Missing docstring in public module

I thought the __init__ in D107 refers to def __init__ situations. D100 is probably wrong here because __init__.py could be considered a public package which is IIRC another D10x code.

The bug here is that we actually don’t tell pydocstyle the correct filename but use a random name. T.i. because pydocstyle can’t read from stdin and we wanted to enable background linting. Does pydocstyle actually ignore everything inside a hypothetical _foo.py?

A solution could be to use, instead of a random filename, a randomly named directory with the correct file name inside it.

I understand. I had confused D107 as referring to __init__.py rather than def __init__(). I see when I run from the command line directly on the package directory it shows D104 rather than D100. I’d like to find out how to exclude D104 on __init__.py only and not on any other public packages. However, that’s probably a topic for pydocstyle itself, not the SublimeLinter integration.

However, the D100 to D104 by using a random directory and correct file name sounds like a good fix.

D104 only triggers on __init__.py. Are there other public packages? Namespaced packages without the __init__.py come to my mind? But how do they work again?

I’m not sure. But I was definitely confused about the meaning of D104. That is the correct error code if __init__.py is missing the docstring. From what I can see, the only bug here is that it is reporting D100 not D104 in Sublimelinter as opposed to plain pydocstyle on the command line.

I released 3.4.0 which should solve this issue.

I installed atom for python programming
and also installed Linter and flake8
packages but everything I write in text editor I get this warning :

D100 — Missing docstring in public module

I already tried

 pip uninstall flake8-docstrings
 pip install Flake8-pep257

How can I fix this warning ?

3 Answers

Its nothing but a comment like this on the top of your program. According to Python Documentation it should be there before every function and program. Here is a simple docstring code

“””Return the pathname of the KOS root directory.”””

You can configure linter-flake8 like any Atom package by editing the settings in Atom -> Preferences -> Packages -> linter-flake8.

Use “ignore error codes” for any errors that you don’t want to see.

install “linter-ui-default dependencies” from the atom packages store..
It helped me.. for the first time it could not be installed. I restarted Atom and it asked me to install this package. clicking on yes it was installed successfully. And now I am not getting any error.

Добавить комментарий