3

#noqa magic comment in python

 2 years ago
source link: https://dev.to/vadimkolobanov/noqa-magic-comment-in-python-33e6
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
#noqa magic comment in python

Adding #noqa to a line means that the linter (a program that automatically checks the quality of the code) should not check this line. Any warnings that the code may have generated will be ignored.

This line may have something that "looks bad" to the linter, but the developer understands and intends to do it for some reason.

Noqa = NO-QA (NO Quality Assurance)

Simply put, lines with #noga at the end will be ignored by linter programs and will not issue any warnings.

Just leave a comment #noqa at the end of the line that triggers a warning from linter, and he will stop paying attention to it.

The most interesting thing is that I got acquainted with NOQA in the root files of the Django framework. The developers just decided to ignore the warnings in some of their imports. Look better visually

from django.core.exceptions import ObjectDoesNotExist
from django.db.models import signals
from django.db.models.aggregates import *  # NOQA
from django.db.models.aggregates import __all__ as aggregates_all
from django.db.models.constraints import *  # NOQA
from django.db.models.constraints import __all__ as constraints_all
from django.db.models.deletion import (
    CASCADE, DO_NOTHING, PROTECT, RESTRICT, SET, SET_DEFAULT, SET_NULL,
    ProtectedError, RestrictedError,
)
from django.db.models.enums import *  # NOQA
from django.db.models.enums import __all__ as enums_all
from django.db.models.expressions import (
    Case, Exists, Expression, ExpressionList, ExpressionWrapper, F, Func,
    OrderBy, OuterRef, RowRange, Subquery, Value, ValueRange, When, Window,
    WindowFrame,
)
from django.db.models.fields import *  # NOQA
from django.db.models.fields import __all__ as fields_all
from django.db.models.fields.files import FileField, ImageField
from django.db.models.fields.json import JSONField
from django.db.models.fields.proxy import OrderWrt
from django.db.models.indexes import *  # NOQA
from django.db.models.indexes import __all__ as indexes_all
from django.db.models.lookups import Lookup, Transform
from django.db.models.manager import Manager
from django.db.models.query import Prefetch, QuerySet, prefetch_related_objects
from django.db.models.query_utils import FilteredRelation, Q
Enter fullscreen modeExit fullscreen mode

If you want to find it yourself, look in django.db.models

Good Luck!

You can also find me on Medium. I will be very glad to have
your attention.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK