Giter Site home page Giter Site logo

rdbende / flake8-tkinter Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 1.0 99 KB

A flake8 plugin that helps you write better Tkinter code

License: MIT License

Python 100.00%
code-quality flake8 flake8-extension flake8-plugin linter linter-plugin tkinter

flake8-tkinter's Introduction

Hello, I'm rdbende ๐Ÿ‘‹

  • ๐Ÿ Most of the time I'm programming in Python. I like making GUIs with GTK4 and sometimes with Tkinter.
  • ๐Ÿ˜ป You might wanna check out my themes for Tkinter. The Sun Valley ttk theme can even make it look like Windows 11!
  • ๐Ÿฆ€ Lately I've been into GUI development using gtk-rs
  • ๐ŸŽน I'm also interested in sound engineering, synths and electronic music, you can find some related projects on my profile
  • ๐Ÿง My distro of choice is Fedora Silverblue ๐Ÿ‘ฃ
  • ๐Ÿ˜ If you're interested in what I'm working on at the moment, check out my Mastodon profile
  • ๐Ÿ“ซ Feel free to contact me via email, or chat with me on Matrix

flake8-tkinter's People

Contributors

insolor avatar rdbende avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

nasingfaund

flake8-tkinter's Issues

tag_bind + statement with body in loop

flake8 --select=TK emits no errors for this:

import tkinter

text = tkinter.Text()
for lel in range(500):
    if True:
        text.tag_bind("foo" + str(lel), print)

AttributeError: 'Attribute' object has no attribute 'id'

flake8-tkinter v0.1.2, Python 3.8

During check of the following code, it throws an exception:

import tkinter as tk

root = tk.Tk()


def func():
    a.b.c


bar=tk.Button(root, text="some text", command=func)
bar.pack(side=tk.TOP, fill=tk.X)

root.mainloop()

Error:

โฏ flake8 bug.py
Traceback (most recent call last):
  File "/home/insolor/.local/bin/flake8", line 8, in <module>
    sys.exit(main())
  File "/home/insolor/.local/lib/python3.8/site-packages/flake8/main/cli.py", line 22, in main
    app.run(argv)
  File "/home/insolor/.local/lib/python3.8/site-packages/flake8/main/application.py", line 360, in run
    self._run(argv)
  File "/home/insolor/.local/lib/python3.8/site-packages/flake8/main/application.py", line 348, in _run
    self.run_checks()
  File "/home/insolor/.local/lib/python3.8/site-packages/flake8/main/application.py", line 262, in run_checks
    self.file_checker_manager.run()
  File "/home/insolor/.local/lib/python3.8/site-packages/flake8/checker.py", line 325, in run
    self.run_serial()
  File "/home/insolor/.local/lib/python3.8/site-packages/flake8/checker.py", line 309, in run_serial
    checker.run_checks()
  File "/home/insolor/.local/lib/python3.8/site-packages/flake8/checker.py", line 589, in run_checks
    self.run_ast_checks()
  File "/home/insolor/.local/lib/python3.8/site-packages/flake8/checker.py", line 496, in run_ast_checks
    for (line_number, offset, text, _) in runner:
  File "/home/insolor/.local/lib/python3.8/site-packages/flake8_tkinter.py", line 172, in run
    visitor.visit(self.tree)
  File "/usr/lib/python3.8/ast.py", line 371, in visit
    return visitor(node)
  File "/usr/lib/python3.8/ast.py", line 379, in generic_visit
    self.visit(item)
  File "/usr/lib/python3.8/ast.py", line 371, in visit
    return visitor(node)
  File "/home/insolor/.local/lib/python3.8/site-packages/flake8_tkinter.py", line 148, in visit_FunctionDef
    self.generic_visit(node)
  File "/usr/lib/python3.8/ast.py", line 379, in generic_visit
    self.visit(item)
  File "/usr/lib/python3.8/ast.py", line 371, in visit
    return visitor(node)
  File "/usr/lib/python3.8/ast.py", line 381, in generic_visit
    self.visit(value)
  File "/usr/lib/python3.8/ast.py", line 371, in visit
    return visitor(node)
  File "/home/insolor/.local/lib/python3.8/site-packages/flake8_tkinter.py", line 151, in visit_Attribute
    if node.value.id == data_dict.get("tkinter_imported_as") and node.attr in {
AttributeError: 'Attribute' object has no attribute 'id'

Better warning messages

I don't want to write a complete novel for every check, but a little explanation would be helpful for those who don't understand why their code is bad.

Also the current messages are really inconsistent in wording.

Better ordering for rules

For example, add=True and tag_bind in loop are in the "Best practices" section. They should be in "Common mistakes"

Keep track of tkinter widgets?

Currently flake8-tkinter assumes that only tkinter widgets can have methods like config, bind or mainloop.

For things like w.update or w["blah"] this won't be enough, because we don't want to warn on a dictionary update, or subscript for example.

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.