Skip to content

Commit

Permalink
Add support for Python 3.12 (#143)
Browse files Browse the repository at this point in the history
* pyproject.toml: Upgrade flake8 and pycodestyle for Python 3.12

* Update poetry.lock

* config: Move inline comments to separate lines for compatibility with flake8 >=6.0

* Coding-Conventions.md: Update E721 example

With pycodestyle 2.11, comparing types with `is` is no longer an error:
PyCQA/pycodestyle#1084

* tests: Update structural_tests to pass with pycodestyle 2.9 and 2.11

pycodestyle 2.11 no longer reports E741 - ambiguous variable name for
`if l == True` because it doesn't contain an assignment.

PyCQA/pycodestyle#1118

* PR workflow: Test with Python 3.12
  • Loading branch information
bkeryan authored Oct 9, 2023
1 parent 08fc62b commit c61b1f7
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
python-version: [3.7, 3.8, 3.9, '3.10', '3.11']
python-version: [3.7, 3.8, 3.9, '3.10', 3.11, 3.12]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand Down
2 changes: 1 addition & 1 deletion docs/Coding-Conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ if cheese is None:
```python
# Bad
if type(num_cheeses) is type(1):
if type(num_cheeses) == type(1):
buy(num_cheeses)
```

Expand Down
33 changes: 22 additions & 11 deletions ni_python_styleguide/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,28 @@ ignore =
# The same goes for the "descriptive"-mood error, if one was to be added to pydocstyle.
D401
# Conflicts with recommending Google style DocStrings
D406 # Section name should end with a newline -> forces a newline at end of DocString
# D406 - Section name should end with a newline -> forces a newline at end of DocString
D406
# Ignoring things enforced by black
D200 # One-line docstring should fit on one line with quotes
D206 # Docstring should be indented with spaces, not tabs
D207 # Docstring is under-indented
D208 # Docstring is over-indented
D210 # No whitespaces allowed surrounding docstring text
D300 # Use """triple double quotes"""
# D200 - One-line docstring should fit on one line with quotes
D200
# D206 - Docstring should be indented with spaces, not tabs
D206
# D207 - Docstring is under-indented
D207
# D208 - Docstring is over-indented
D208
# D210 - No whitespaces allowed surrounding docstring text
D210
# D300 - Use """triple double quotes"""
D300
# Conflicts with other codes
D203 # 1 blank line required before class docstring
D213 # Multi-line docstring summary should start at the second line
D400 # First line should end with a period
# D203 - 1 blank line required before class docstring
D203
# D213 - Multi-line docstring summary should start at the second line
D213
# D400 - First line should end with a period
D400
# Recommending Google, so these don't apply - http://www.pydocstyle.org/en/stable/error_codes.html#:~:text=The%20google%20convention%20added%20in%20v4.0.0
D203
D204
Expand All @@ -99,7 +109,8 @@ ignore =
D409
D413
# flake8-import-order
I101 # The names in your from import are in the wrong order. (Enforced by E401)
# I101 - The names in your from import are in the wrong order. (Enforced by E401)
I101

# We want to ignore missing docstrings in test methods as they are self documenting
per-file-ignores= tests/**/test_*.py:D100,D103
Expand Down
57 changes: 55 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ include = ["ni_python_styleguide/config.toml"]
python = "^3.7"

# Tools we aggregate
flake8 = "^5.0"
flake8 = [
{version = "^5.0", python = ">=3.7,<3.12"},
{version = "^6.1", python = "^3.12"},
]
pycodestyle = [
{version = "^2.9", python = ">=3.7,<3.12"},
{version = "^2.11", python = "^3.12"},
]
black = ">=23.1"

# Additional support libraries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ def return_no_cheese_found(self):
except:
pass

l = 5
i = 3
j = 5

if l == True:
return False
l = (i == True)

return cheese_found
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ class Cheese_Shop: # noqa: D101, N801 - Missing docstring in public class (auto
except: # noqa: E722 - do not use bare 'except' (auto-generated noqa)
pass

l = 5 # noqa: E741 - ambiguous variable name 'l' (auto-generated noqa)
i = 3 # noqa: F841 - local variable 'i' is assigned to but never used (auto-generated noqa)
i = 3
j = 5 # noqa: F841 - local variable 'j' is assigned to but never used (auto-generated noqa)

if l == True: # noqa: E741, E712 - ambiguous variable name 'l' (auto-generated noqa), comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa)
return False
l = (i == True) # noqa: E712, E741, F841 - comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa), ambiguous variable name 'l' (auto-generated noqa), local variable 'l' is assigned to but never used (auto-generated noqa)

return cheese_found
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ def return_no_cheese_found(self):
except: # noqa: E722 - do not use bare 'except' (auto-generated noqa)
pass

l = 5 # noqa: E741 - ambiguous variable name 'l' (auto-generated noqa)
i = 3 # noqa: F841 - local variable 'i' is assigned to but never used (auto-generated noqa)
i = 3
j = 5 # noqa: F841 - local variable 'j' is assigned to but never used (auto-generated noqa)

if (
l
l = ( # noqa: E741, F841 - ambiguous variable name 'l' (auto-generated noqa), local variable 'l' is assigned to but never used (auto-generated noqa)
i
== True # noqa: E712 - comparison to True should be 'if cond is True:' or 'if cond:' (auto-generated noqa)
):
return False
)

return cheese_found

0 comments on commit c61b1f7

Please sign in to comment.