aider: Removed unused imports and changed comparison to None to use is instead of == in aider/history.py, aider/models/__init__.py, and aider/models/openrouter.py.

# Aider chat conversation:

USER: I ran this command:

 pre-commit run --all-files

And got this output:

isort....................................................................Passed
black....................................................................Passed
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

aider/history.py:4:1: F401 'tiktoken' imported but unused
import tiktoken
^
aider/models/__init__.py:2:1: F401 '.openai.OpenAIModel' imported but unused
from .openai import OpenAIModel
^
aider/models/__init__.py:3:1: F401 '.openrouter.OpenRouterModel' imported but unused
from .openrouter import OpenRouterModel
^
aider/models/openrouter.py:26:33: E711 comparison to None should be 'if cond is None:'
        if cached_model_details == None:
                                ^

ASSISTANT: It seems like there are some unused imports and a comparison to None that is not following the Pythonic way. To fix these issues, we need to modify the following files:

1. `aider/history.py`
2. `aider/models/__init__.py`
3. `aider/models/openrouter.py`

Please add these files to the chat so I can propose the necessary changes.

USER: I added these *read-write* files: aider/history.py, aider/models/openrouter.py, aider/models/__init__.py

ASSISTANT: Great! Now, let's make the necessary changes to these files.

First, in `aider/history.py`, we need to remove the unused import `tiktoken`.

```python
aider/history.py
<<<<<<< HEAD
import tiktoken
=======
>>>>>>> updated
```

Next, in `aider/models/__init__.py`, we need to remove the unused imports `OpenAIModel` and `OpenRouterModel`.

```python
aider/models/__init__.py
<<<<<<< HEAD
from .openai import OpenAIModel
from .openrouter import OpenRouterModel
=======
>>>>>>> updated
```

Finally, in `aider/models/openrouter.py`, we need to change the comparison to None to use `is` instead of `==`.

```python
aider/models/openrouter.py
<<<<<<< HEAD
        if cached_model_details == None:
=======
        if cached_model_details is None:
>>>>>>> updated
```

These changes should resolve the issues reported by the `flake8` linter.
This commit is contained in:
Paul Gauthier 2023-09-01 15:54:22 -07:00
parent 1334392418
commit 3045c5e94d
3 changed files with 1 additions and 4 deletions

View file

@ -1,7 +1,6 @@
import argparse
import json
import tiktoken
from aider import models, prompts
from aider.dump import dump # noqa: F401

View file

@ -1,6 +1,4 @@
from .model import Model
from .openai import OpenAIModel
from .openrouter import OpenRouterModel
GPT4 = Model.create("gpt-4")
GPT35 = Model.create("gpt-3.5-turbo")

View file

@ -23,7 +23,7 @@ class OpenRouterModel(Model):
self.tokenizer = tiktoken.get_encoding("cl100k_base")
global cached_model_details
if cached_model_details == None:
if cached_model_details is None:
cached_model_details = openai.Model.list().data
found = next(
(details for details in cached_model_details if details.get("id") == name), None