Giter Club home page Giter Club logo

flake8-string-format's People

Contributors

alexarcpy avatar wwuck avatar xzise avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

flake8-string-format's Issues

docstrings with signature on first line including {}

While this isnt pretty, and they might be interested in changing it as it only occurs in a few modules, it is causing false positives.

'''API Function: insert(search_type, data, metadata={}, parent_key=None,  info={}, use_id=False, triggers=True)
...
'''

Modules with this syntax (All start with 'API Function: ' or 'Function: ')
https://github.com/Southpaw-TACTIC/TACTIC/blob/master/src/client/tactic_client_lib/tactic_server_stub.py
https://github.com/Southpaw-TACTIC/TACTIC/blob/master/src/pyasm/application/common/application.py
https://github.com/Southpaw-TACTIC/TACTIC/blob/master/src/pyasm/interpreter/tactic_client_lib/tactic_server_stub.py
https://github.com/Southpaw-TACTIC/TACTIC/blob/master/src/pyasm/prod/service/api_xmlrpc.py

Feature request: f-string validation

I'm not sure if this plugin is intended to check f-string (Python 3.6+).

I personally would like to have a rule that forbids to use f-strings without any variables/expressions/formatting inside, for example:

print(f"Hello world!")  # should be forbidden, convert to plain string, remove f prefix
print(f"2 + 2 is {2 + 2}")  # ok

Warn about missing formatting

I thought my code was ok until I ran it and found output like:

{0} branch does not exist locally

Looking at the code, it was obvious:

print('{0} branch does not exist locally')

I forgot to format the string: .format(branch)

Would it be possible to warn about this kind of errors?

P103 in regex

link_regex = re.compile(r'\[\[(?P<title>[^\]|[<>{}]*)(\|.*?)?\]\]')

produces

./pywikibot/__init__.py:643:25: P103 other string does contain unindexed parameters

visit_Str and visit_Bytes have been deprecated in favor of visit_Constant in Python 3.8

flake8_string_format.py
42:    def visit_Str(self, node):
45:    def visit_Bytes(self, node):

Generates the below warnings in Python 3.8

test_flake8_string_format.py: 301 tests with warnings
  /usr/lib/python3.8/ast.py:360: PendingDeprecationWarning: visit_Str is deprecated; add visit_Constant
    return visitor(node)

test_flake8_string_format.py: 144 tests with warnings
  /usr/lib/python3.8/ast.py:360: PendingDeprecationWarning: visit_Bytes is deprecated; add visit_Constant
    return visitor(node)

Don't check docstrings

Actual docstrings are most likely not a problem for this. Could also add a parameter to enable that too.

Question is how to detect a docstring? It could check for class or function definition and ignore the first Expr?

sdist release?

Hi @xZise!

Would it be possible to make a source release that go along with the wheel release?

A tool called zc.buildout (PyPI) does not support wheels right now and it's being used by quite a lot of people, which, currently can not use your awesome flake8 plugin :S

Thanks in advance,
Gil

Double brackets using MW template format

The MW uses {{…}} for templates and {{:Bla}} is a valid name which shouldn't be considered a problem. One way to mitigate (at the moment) would be to use {{ :Bla}} because Python doesn't allow { }.format(42).

Another way would be to ignore constellations where there are an even number of brackets on each side as they aren't parsed but its number gets halved.

AssertionError on Python 2.6 - 3.4

I'm getting this in Travis CI on all Python versions. Unfortunately I don't seem to be able to reproduce it locally. Any ideas?

Traceback (most recent call last):
  File "/home/travis/virtualenv/python2.7.9/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/flake8/main.py", line 28, in main
    flake8_style = get_style_guide(parse_argv=True)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/flake8/engine.py", line 234, in get_style_guide
    styleguide = StyleGuide(**kwargs)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/flake8/engine.py", line 154, in __init__
    self._styleguide = kwargs.pop('styleguide', NoQAStyleGuide(**kwargs))
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pycodestyle.py", line 1833, in __init__
    arglist, parse_argv, config_file, parser)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pycodestyle.py", line 2120, in process_options
    options = read_config(options, args, arglist, parser)
  File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/pycodestyle.py", line 2076, in read_config
    assert opt_type in ('store_true', 'store_false')
AssertionError

string used with comparisons such as == and in

Two cases in TACTIC

src/tactic/ui/panel/custom_layout_wdg.py:611:36: P103 other string does contain unindexed parameters
        if not plugin or plugin == '{}':
...
src/pyasm/common/common.py:732:26: P103 other string does contain unindexed parameters
            elif char in '''!@$%^&*()={}[]:"|;'\\<>?''':

If a whitelist is added, many string methods such as str.strip are known to be safe.

AssertionError when format contains starred unpacking.

One of the strings that cause error:

'{}.{}.{}-rc.{}'.format(*parts[:3], pre + 1)

Traceback:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/multiprocessing/pool.py", line 121, in worker
    result = (True, func(*args, **kwds))
  File "/usr/local/lib/python3.7/multiprocessing/pool.py", line 44, in mapstar
    return list(map(*args))
  File "/home/gram/.local/share/dephell/venvs/dephell-nLn6/flake8/lib/python3.7/site-packages/flake8/checker.py", line 669, in _run_checks
    return checker.run_checks()
  File "/home/gram/.local/share/dephell/venvs/dephell-nLn6/flake8/lib/python3.7/site-packages/flake8/checker.py", line 608, in run_checks
    self.run_ast_checks()
  File "/home/gram/.local/share/dephell/venvs/dephell-nLn6/flake8/lib/python3.7/site-packages/flake8/checker.py", line 504, in run_ast_checks
    for (line_number, offset, text, check) in runner:
  File "/home/gram/.local/share/dephell/venvs/dephell-nLn6/flake8/lib/python3.7/site-packages/flake8_string_format.py", line 299, in run
    assert not has_starargs or isinstance(call.args[-1], ast.Starred)
AssertionError

Expected behavior: plugin should just ignore code lines that cannot be processed.

Docstrings with dictionary examples

I'm having false positives of P102 docstring does contain unindexed parameters because of this line:

    {'description': '', 'extension': {}, 'time': ��1N|�r�, 'tid': '\x03\xca1N|\xa9r\x99', 'serial': '\x03\xca1N|\xa9r\x99', 'user_name': '', 'size': 1042}

This line is used in the docstring to give some documentation of the motivation of some code decisions in the module.

This is somewhat similar to #7.

P103 in "{}" string

Hi, how to work with such case:

code line from piece with ORM model

document_uri = Column(JSONB, nullable=False, server_default="{}")

produces error: P103 other string does contain unindexed parameters

but it's not recognized by python as parameter in string, it's recognized just as is - {}

Two false positives in roundup unittest TestCase

I've been testing this on a few very large repos, and finding the occasional error

In roundup (http://www.roundup-tracker.org/index.html), only the following:

test/test_templating.py:350:0: P103 other string does contain unindexed parameters
test/test_mailgw.py:2826:65: P103 other string does contain unindexed parameters
test/test_mailgw.py:2842:65: P103 other string does contain unindexed parameters
test/test_mailgw.py:2857:65: P103 other string does contain unindexed parameters

http://sourceforge.net/p/roundup/code/ci/default/tree/test/test_templating.py
http://sourceforge.net/p/roundup/code/ci/default/tree/test/test_mailgw.py

Definitely within the realms of reasonable use of noqa, but maybe worth fixing.

Feature request: Change error code prefix to multiple characters

I would like to request changing the error code prefix from P to STRF.

This plugin is currently conflicting with flake8-exact-pin which also uses the P prefix for flake8 error codes.

As of flake8 v3.0, plugins are no longer required to have error codes exactly four characters long and the flake8 documentation recommends using a longer prefix to avoid conflicts with other plugins:

Flake8 requires each entry point to be unique amongst all plugins installed in the users environment. Selecting an entry point that is already used can cause plugins to be deactivated without warning!

Please Note: Your entry point does not need to be exactly 4 characters as of Flake8 3.0. Consider using an entry point with 3 letters followed by 3 numbers (i.e. ABC123 ).

flake8-strings is already using error prefix STR which is why I have suggested STRF.

AssertionError when using *args with python3.5

With python 3.5, when I let flake8 with flake8-string-format run over this:

a = ['bla']
print("foo{}bar".format(*a))

I get:

Traceback (most recent call last):
  File "./.venv-flakes/bin/flake8", line 11, in <module>
    sys.exit(main())
  File ".../site-packages/flake8/main.py", line 33, in main
    report = flake8_style.check_files()
  File ".../site-packages/flake8/engine.py", line 181, in check_files
    return self._retry_serial(self._styleguide.check_files, paths=paths)
  File ".../site-packages/flake8/engine.py", line 172, in _retry_serial
    return func(*args, **kwargs)
  File ".../site-packages/pep8.py", line 1842, in check_files
    runner(path)
  File ".../site-packages/flake8/engine.py", line 126, in input_file
    return fchecker.check_all(expected=expected, line_offset=line_offset)
  File ".../site-packages/pep8.py", line 1574, in check_all
    self.check_ast()
  File ".../site-packages/pep8.py", line 1521, in check_ast
    for lineno, offset, text, check in checker.run():
  File ".../site-packages/flake8_string_format.py", line 288, in run
    assert isinstance(call.args, ast.Starred) is bool(has_starargs)
AssertionError

It works fine with 3.4.

With 3.5, it seems like call.args is a list of ast.Starred objects, and
thus the isinstance() check fails:

(Pdb) has_starargs
1
(Pdb) isinstance(call.args, ast.Starred)
False
(Pdb) call.args
[<_ast.Starred object at 0x7fb97df31f28>]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.