Skip to content

Commit

Permalink
Add support for Python 3.12
Browse files Browse the repository at this point in the history
Python 3.12 configparser removed SafeConfigParser.
python/cpython#89336 (comment)

leading to this issue

```
Traceback (most recent call last):
  File "/home/user/.cache/pypoetry/virtualenvs/chapter-marker-bSlZRqHo-py3.12/bin/pflake8", line 5, in <module>
    from pflake8.__main__ import main
  File "/home/user/.cache/pypoetry/virtualenvs/chapter-marker-bSlZRqHo-py3.12/lib/python3.12/site-packages/pflake8/__init__.py", line 54, in <module>
    class DivertingSafeConfigParser(ConfigParserTomlMixin, configparser.SafeConfigParser):
                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'configparser' has no attribute 'SafeConfigParser'. Did you mean: 'RawConfigParser'
```
  • Loading branch information
fliiiix committed Oct 10, 2023
1 parent 16b9dd4 commit 44bf22c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pflake8/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@ class DivertingConfigParser(ConfigParserTomlMixin, configparser.ConfigParser):
pass


class DivertingSafeConfigParser(ConfigParserTomlMixin, configparser.SafeConfigParser):
pass
try:

class DivertingSafeConfigParser(
ConfigParserTomlMixin, configparser.SafeConfigParser
):
pass

configparser.SafeConfigParser = DivertingSafeConfigParser
except AttributeError:
pass # does not exist on Python 3.12 (https://github.com/python/cpython/issues/89336#issuecomment-1094366625)


configparser.RawConfigParser = DivertingRawConfigParser
configparser.ConfigParser = DivertingConfigParser
configparser.SafeConfigParser = DivertingSafeConfigParser


class FixFilenames(ast.NodeTransformer):
Expand Down

0 comments on commit 44bf22c

Please sign in to comment.