Skip to content

Commit

Permalink
Refactor (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbende authored Aug 11, 2022
1 parent 39595cf commit e6312da
Show file tree
Hide file tree
Showing 33 changed files with 509 additions and 438 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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

## Installation

```
pip install flake8-tkinter
```


## List of warnings

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

### `TK131`
Don't assign to `w.grid()` / `w.pack()` / `w.place()`, it's return value is `None`

```diff
- btn = ttk.Button().grid()
+ btn = ttk.Button()
+ btn.grid()
```

### `TK201`
Don't use `from tkinter import *`

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

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

- Opinionated suggestions
- [ ] Suggest changing things like `root.wm_title()` to `root.title()` (tho I use `wm_` quite often) (**TK305**)
- [ ] Suggest changing things like `root.wm_title()` to `root.title()` (tho I use `wm_attributes` quite often, probably that should be an exception) (**TK305**)
- [ ] Warn when calling `mainloop()` on something other than the root window (**TK303**)
- [ ] Suggest using more clear binding sequences, like `<Button-1>` instead of `<1>` and `<Key-a>` instead of `<a>` (**TK301**)
- [ ] Warn if a parent is not specified (?) (**TK306**)
Expand Down
8 changes: 4 additions & 4 deletions flake8_tkinter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import annotations

import ast
from collections.abc import Generator
from dataclasses import dataclass
from typing import Generator

from .visitor import Visitor

__version__ = "0.2.5"
__version__ = "0.5.0"


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

for line, col, msg in visitor.problems:
yield line, col, msg, None
for error in visitor.errors:
yield error.line, error.col, error.msg, None
22 changes: 0 additions & 22 deletions flake8_tkinter/checkers/TK102.py

This file was deleted.

80 changes: 0 additions & 80 deletions flake8_tkinter/checkers/TK111.py

This file was deleted.

52 changes: 0 additions & 52 deletions flake8_tkinter/checkers/TK112.py

This file was deleted.

16 changes: 0 additions & 16 deletions flake8_tkinter/checkers/TK201.py

This file was deleted.

16 changes: 0 additions & 16 deletions flake8_tkinter/checkers/TK202.py

This file was deleted.

14 changes: 0 additions & 14 deletions flake8_tkinter/checkers/TK211.py

This file was deleted.

24 changes: 0 additions & 24 deletions flake8_tkinter/checkers/TK221.py

This file was deleted.

25 changes: 0 additions & 25 deletions flake8_tkinter/checkers/TK231.py

This file was deleted.

47 changes: 0 additions & 47 deletions flake8_tkinter/checkers/TK232.py

This file was deleted.

Loading

0 comments on commit e6312da

Please sign in to comment.