Giter VIP home page Giter VIP logo

flake8-print's People

Contributors

cjkjvfnby avatar dirn avatar gforcada avatar jayvdb avatar jbkahn avatar martinthoma avatar melevir avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

flake8-print's Issues

Exception on Windows with Python 2.7 since 1.6

Traceback (most recent call last):
  File "C:\Python27\Lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\Lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File ".tox\flake8\Scripts\flake8.EXE\__main__.py", line 9, in <module>
  File ".tox\flake8\lib\site-packages\flake8\main.py", line 33, in main
    report = flake8_style.check_files()
  File ".tox\flake8\lib\site-packages\pep8.py", line 1670, in check_files
    self.input_dir(path)
  File ".tox\flake8\lib\site-packages\pep8.py", line 1706, in input_dir
    runner(os.path.join(root, filename))
  File ".tox\flake8\lib\site-packages\flake8\engine.py", line 95, in input_file
    return fchecker.check_all(expected=expected, line_offset=line_offset)
  File ".tox\flake8\lib\site-packages\pep8.py", line 1412, in check_all
    self.check_ast()
  File ".tox\flake8\lib\site-packages\pep8.py", line 1359, in check_ast
    for lineno, offset, text, check in checker.run():
  File ".tox\flake8\lib\site-packages\flake8_print.py", line 27, in run
    errors = check_tree_for_print_statements(self.tree, noqa)
  File ".tox\flake8\lib\site-packages\flake8_print.py", line 48, in check_tree_for_print_statements
    if ((isinstance(node, ast.Call) and node.func.id == 'print') or (hasattr(ast, 'Print') and isinstance(node, ast.Print) and node.lineno not in noqa)) and node.lineno not in noqa:
AttributeError: 'Attribute' object has no attribute 'id'

version 5.0.0?

There's a version 5.0.0 on PyPI, but no trace of it on GitHub. Where's the code?

Putting back "# noqa"

You could (although I haven't tested it, and I'm afraid don't have time to do a PR) tokenize the source file to identify lines with # noqa comments:

import tokenize
import ast

with open('somefile') as fin:
    source = fin.read()
    parsed = ast.parse(source)

tokens = tokenize.generate_tokens(lambda L=iter(source.splitlines()): next(L))
noqa = {
    token[2][0] for token in tokens 
    if token[0] == tokenize.COMMENT and token[1].endswith('noqa')
}

Then carry on with parsed as you are, but exclude messages whose line is present in noqa...

adding support for `traceback.print_*` functions

Hi,

It would be great to add all the print functions of traceback.print_* in this library detection as well.

I'm using this plugin as a way to stop the usage of prints without the use of loggers, traceback.print_* sometimes are used in this context

try:
   a = 1/0
except Exception as e:
   print(e)
   traceback.print_exc()

I would like to prohibit these functions as well since they follow the same merit, have the print name in it, and from the standard library

Release of pycodestyle 2.4.0 breaks flake8-print

While running flake8 linter with flake8-print I get an error due to flake8-print bringing in version 2.4.0 of pycodestyle. Suggested PR to fix #32

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2416, in resolve
    return functools.reduce(getattr, self.attrs, module)
AttributeError: module 'pycodestyle' has no attribute 'break_around_binary_operator'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 178, in load_plugin
    self._load(verify_requirements)
  File "/usr/local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 150, in _load
    self._plugin = resolve()
  File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2418, in resolve
    raise ImportError(str(exc))
ImportError: module 'pycodestyle' has no attribute 'break_around_binary_operator'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/usr/local/lib/python3.6/site-packages/flake8/main/application.py", line 396, in run
    self._run(argv)
  File "/usr/local/lib/python3.6/site-packages/flake8/main/application.py", line 383, in _run
    self.initialize(argv)
  File "/usr/local/lib/python3.6/site-packages/flake8/main/application.py", line 365, in initialize
    self.find_plugins()
  File "/usr/local/lib/python3.6/site-packages/flake8/main/application.py", line 191, in find_plugins
    self.check_plugins.load_plugins()
  File "/usr/local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 423, in load_plugins
    plugins = list(self.manager.map(load_plugin))
  File "/usr/local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 311, in map
    yield func(self.plugins[name], *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 421, in load_plugin
    return plugin.load_plugin()
  File "/usr/local/lib/python3.6/site-packages/flake8/plugins/manager.py", line 186, in load_plugin
    raise failed_to_load
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "pycodestyle.break_around_binary_operator" due to module 'pycodestyle' has no attribute 'break_around_binary_operator'.

Question: support for pprint detection

I usually use python pprint module when debugging.
Would it be nice to add another rule for this case? especially since it's not third-party but standard python.

Let me know if it seems useful, i'd be glad to submit a PR

what is this for?

Hello,

it would be nice to know why someone would want to prevent the use of print() ?
Maybe you can extend the README file to explain it?

AttributeError: 'Name' object has no attribute 'arg'

When upgrading to latest version of flake8-print (3.0.0) and using flake8 (3.5.0) I get the above error

[anders:~/tmp] [e] 7s $ flake8 -j 1 e/
Traceback (most recent call last):
  File "/home/anders/tmp/e/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/home/anders/tmp/e/local/lib/python2.7/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/home/anders/tmp/e/local/lib/python2.7/site-packages/flake8/main/application.py", line 396, in run
    self._run(argv)
  File "/home/anders/tmp/e/local/lib/python2.7/site-packages/flake8/main/application.py", line 384, in _run
    self.run_checks()
  File "/home/anders/tmp/e/local/lib/python2.7/site-packages/flake8/main/application.py", line 310, in run_checks
    self.file_checker_manager.run()
  File "/home/anders/tmp/e/local/lib/python2.7/site-packages/flake8/checker.py", line 321, in run
    self.run_serial()
  File "/home/anders/tmp/e/local/lib/python2.7/site-packages/flake8/checker.py", line 305, in run_serial
    checker.run_checks()
  File "/home/anders/tmp/e/local/lib/python2.7/site-packages/flake8/checker.py", line 579, in run_checks
    self.run_ast_checks()
  File "/home/anders/tmp/e/local/lib/python2.7/site-packages/flake8/checker.py", line 493, in run_ast_checks
    for (line_number, offset, text, check) in runner:
  File "/home/anders/tmp/e/local/lib/python2.7/site-packages/flake8_print.py", line 88, in run
    parser.visit(self.tree)
  File "/usr/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/usr/lib/python2.7/ast.py", line 249, in generic_visit
    self.visit(item)
  File "/usr/lib/python2.7/ast.py", line 241, in visit
    return visitor(node)
  File "/home/anders/tmp/e/local/lib/python2.7/site-packages/flake8_print.py", line 49, in visit_FunctionDef
    if arg.arg in PRINT_FUNCTION_NAMES:
AttributeError: 'Name' object has no attribute 'arg'

Doesn't install from setup.py

Not sure if this is a supported usecase, but it looks like this library breaks when trying to install from a setup.py file.

Directory based subset

Is there a way to select a directory? I really only care about prints in my package; in scripts, examples, and tests they are valid. I want to keep running the rest of flake8 on the other directories, though. I think I can make this work via pre-commit and splitting the check in two, but is there a better way? Thank you for this useful package!

Python 2.6 support

Changed in version 2.7: The positional argument specifiers can be omitted, so '{} {}' is equivalent to '{0} {1}'.

Python 2.6 needs explicit argument specifiers.

Publish on pypi

Could you publish this tool on pypi , so that it is easier to install.

No license file

Thanks for writing this plugin!

I noticed that while setup.py says the license of the package is MIT, there is no license file in the repository (and thus no license included in the package either).

Plugin doesn't detect prints

Hi

I'm not sure what's going on here, but I can't seem to get the plugin to work:

root@9eab8a7ef08d:/code# flake8 --version
c3.5.0 (flake8-blind-except: 0.1.1, flake8-print: 3.0.1, flake8_pep3101: 0.1, import-order: 0.15, mccabe: 0.6.1, pycodestyle: 2.3.1, pyflakes: 1.6.0) CPython 2.7.6 on Linux
root@9eab8a7ef08d:/code# cat test.py
import this

print "hello world"

a = b
root@9eab8a7ef08d:/code# flake8 test.py
test.py:1:1: F401 'this' imported but unused
test.py:5:5: F821 undefined name 'b'

Also catches print in strings

Reports a false positive for this multiline string at least:

email_msg = """MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
"""

Chosen error code clashes with flake8-todos

See the issue I opened on flake8, which was promptly closed and redirected here: PyCQA/flake8#1563

Comparing these two lines:

https://github.com/orsinium-labs/flake8-todos/blob/master/setup.py#L39
https://github.com/JBKahn/flake8-print/blob/master/pyproject.toml#L45

We see that flake8-print and flake8-todos are both attempting to reserve T00 for their error codes. This prevents anyone from installing both plugins.

Could one of these tools please change their error code prefix? I would open this issue on flake8-todos, but it appears no one can open issues there.

Make flake8-print available as a pre-commit hook?

We've frequently had to catch print statements in PRs that should use loggers, and this seems like exactly the tool we need! 😃

However, would it be possible to make this available as a pre-commit hook (docs)? We would want to catch print statements before the commit is created, even if the developer forgets to run flake8 locally.

Tuple parameter unpacking makes flake8-print fail

Steps to reproduce

  1. Create a test.py file with the following contents:
def fail((a, b, c)):
    pass
  1. Run flake8 test.py (with flake8-print installed).

Expected: flake8 run passes without raising any issues.
Actual: flake8 fails with the following traceback:

(venv) [test_flake8_print] flake8 test.py
Traceback (most recent call last):
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/lib/python2.7/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/lib/python2.7/site-packages/flake8/main/application.py", line 396, in run
    self._run(argv)
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/lib/python2.7/site-packages/flake8/main/application.py", line 384, in _run
    self.run_checks()
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/lib/python2.7/site-packages/flake8/main/application.py", line 310, in run_checks
    self.file_checker_manager.run()
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/lib/python2.7/site-packages/flake8/checker.py", line 319, in run
    self.run_parallel()
  File "/Users/wojcikstefan/Repos/test_flake8_print/venv/lib/python2.7/site-packages/flake8/checker.py", line 288, in run_parallel
    for ret in pool_map:
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py", line 668, in next
    raise value
AttributeError: 'Tuple' object has no attribute 'id'

Reason

I traced the problem back to this line:

if arg.id in PRINT_FUNCTION_NAMES:

When the function definition contains a tuple parameter one of the args is an _ast.Tuple object, not the expected _ast.Name. _ast.Tuple doesn't have the id attribute, hence arg.id raises the AttributeError seen in the traceback.

Note that tuple parameter unpacking has been removed in Python 3 via PEP 3113, so this is only a bug in handling Python 2 files.

Inline #nopep8 comment has no effect with 3.1.3

This might be related to #40 but violation is different, so I'm making new issue.

Our builds on CI server started to fail just when 3.1.3 was released. Seems like inline # nopep8 comment has no effect anymore and on such line:

...
print(foo) # nopep8
...

results in violation error:

my_project/print_mailer.py:35:9: T001 print found.

It was just bump of patch part of semver so CI server fetched the most recent version and older version was present on my local machine. Took me a while to track down what was causing this, but everything seems to be working fine wit 3.1.1.

Build to wheel

It would be great if this project supported building to wheels as this would speed up installation for users and mean that they didn't need to run setup.py.

I'd be happy to put together a PR for this at some point if you'd be open to merging it.
Likely I'd base this on one of my existing projects which does build to wheels and introduce a script which wrapped the build and upload steps (with the help of the twine package).

`noqa` comment does bring up new violations

After updating to 3.1.3 I have new violations.

Let's start with the regular print usage:

print(1)

Output:

» flake8 ex.py

ex.py

  1:1      T001  print found.
  print(1)
  ^

Full list of violations and explanations:
https://wemake-python-stylegui.de/en/0.12.5/pages/usage/violations/

That's ok. Now, let's ignore this violation with a noqa comment:

print(1)  # noqa: T001

Output:

» flake8 ex.py

ex.py

  1:1      T002  Python 2.x reserved word print used.
  print(1)  # noqa: T001
  ^

Full list of violations and explanations:
https://wemake-python-stylegui.de/en/0.12.5/pages/usage/violations/

That's not what I expect to happen. I expect that after my noqa comment is created I will receive 0 violations. Moreover, I am not sure how comment can change print violation code.

This all happed somewhere at this point: wemake-services/wemake-python-styleguide#964

With 3.1.1 everything works as it should.

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.