Skip to content

Commit e6312da

Browse files
authored
Refactor (#7)
1 parent 39595cf commit e6312da

33 files changed

+509
-438
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Flake8 plugin to detect (too) common mistakes and bad practices in Tkinter projects
44

5+
## Installation
6+
7+
```
8+
pip install flake8-tkinter
9+
```
10+
511

612
## List of warnings
713

@@ -32,6 +38,15 @@ Calling a function with arguments instead of using a lambda or a partial functio
3238
+ ttk.Button(command=lambda: foo(bar, baz))
3339
```
3440

41+
### `TK131`
42+
Don't assign to `w.grid()` / `w.pack()` / `w.place()`, it's return value is `None`
43+
44+
```diff
45+
- btn = ttk.Button().grid()
46+
+ btn = ttk.Button()
47+
+ btn.grid()
48+
```
49+
3550
### `TK201`
3651
Don't use `from tkinter import *`
3752

@@ -113,7 +128,7 @@ Don't use things like `add="+"`. Use a boolean instead
113128
## More planned warnings
114129

115130
- Common mistakes
116-
- [ ] Warn when assigning to result of `w.pack()` | `w.grid()` | `w.place()` call (`None`) (**TK131**)
131+
- [x] Warn when assigning to result of `w.pack()` | `w.grid()` | `w.place()` call (`None`) (**TK131**)
117132
- [ ] Warn when using more than one`Tk` instance: child windows must be created from `Toplevel` class (**TK101**)
118133
- [x] Warn when using more than one `mainloop()` call (**TK102**)
119134
- [ ] Suggest using `w.after(ms)` instead of `time.sleep(s)` (**TK121**)
@@ -136,7 +151,7 @@ Don't use things like `add="+"`. Use a boolean instead
136151
- [x] Warn when using `tag_bind` inside a loop, but not storing the Tcl command (can cause memory leaks later) (**TK232**)
137152

138153
- Opinionated suggestions
139-
- [ ] Suggest changing things like `root.wm_title()` to `root.title()` (tho I use `wm_` quite often) (**TK305**)
154+
- [ ] Suggest changing things like `root.wm_title()` to `root.title()` (tho I use `wm_attributes` quite often, probably that should be an exception) (**TK305**)
140155
- [ ] Warn when calling `mainloop()` on something other than the root window (**TK303**)
141156
- [ ] Suggest using more clear binding sequences, like `<Button-1>` instead of `<1>` and `<Key-a>` instead of `<a>` (**TK301**)
142157
- [ ] Warn if a parent is not specified (?) (**TK306**)

flake8_tkinter/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from __future__ import annotations
22

33
import ast
4+
from collections.abc import Generator
45
from dataclasses import dataclass
5-
from typing import Generator
66

77
from .visitor import Visitor
88

9-
__version__ = "0.2.5"
9+
__version__ = "0.5.0"
1010

1111

1212
@dataclass(frozen=True)
@@ -19,5 +19,5 @@ def run(self) -> Generator[tuple[int, int, str, None], None, None]:
1919
visitor = Visitor()
2020
visitor.visit(self.tree)
2121

22-
for line, col, msg in visitor.problems:
23-
yield line, col, msg, None
22+
for error in visitor.errors:
23+
yield error.line, error.col, error.msg, None

flake8_tkinter/checkers/TK102.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

flake8_tkinter/checkers/TK111.py

Lines changed: 0 additions & 80 deletions
This file was deleted.

flake8_tkinter/checkers/TK112.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

flake8_tkinter/checkers/TK201.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

flake8_tkinter/checkers/TK202.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

flake8_tkinter/checkers/TK211.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

flake8_tkinter/checkers/TK221.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

flake8_tkinter/checkers/TK231.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)