python-hyper / h11

A pure-Python, bring-your-own-I/O implementation of HTTP/1.1
https://h11.readthedocs.io/
MIT License
490 stars 62 forks source link

Update isort command #137

Closed memst closed 3 years ago

memst commented 3 years ago

Isort 5.0.0 has been released over a year ago and many options have been deprecated as they are now the default behaviour.

Current command for isort in CONTRIBUTING.md causes an error:

isort: error: unrecognized arguments: h11 bench examples fuzz

The PR removes all arguments that are unnecessary in the current version.

If support for the old versoin of isort is still needed, a compromise can be reached by using the command:

$ isort --apply --settings-path setup.cfg --recursive h11 bench examples fuzz

In that case the old version will work but skip the __init__.py file, and the new version will work but give deprecation warnings.

pquentin commented 3 years ago

@memst Would it be easier to just use isort --profile black and remove all other settings?

memst commented 3 years ago

Removing all of the config could be a good idea. The only option that currently does something for the repository and isn't included in --profile black is order_by_type

order_by_type: If set to true - isort will create separate sections within "from" imports for CONSTANTS, Classes, and modules/functions. (reference)

Currently false:

from typing import Any, cast, Dict, List, Tuple, Union

Black (also default) true:

from typing import Any, Dict, List, Tuple, Union, cast
Complete diff with `--profile Black`: ```git diff --git a/h11/_connection.py b/h11/_connection.py index bcd3089..4140de0 100644 --- a/h11/_connection.py +++ b/h11/_connection.py @@ -9,8 +9,8 @@ from ._state import * # Import all state sentinels from ._state import _SWITCH_CONNECT, _SWITCH_UPGRADE, ConnectionState from ._util import ( # Import the internal things we need LocalProtocolError, - make_sentinel, RemoteProtocolError, + make_sentinel, ) from ._writers import WRITERS diff --git a/h11/_events.py b/h11/_events.py index ebbf10f..1103898 100644 --- a/h11/_events.py +++ b/h11/_events.py @@ -8,11 +8,11 @@ import re from abc import ABC from dataclasses import dataclass, field -from typing import Any, cast, Dict, List, Tuple, Union +from typing import Any, Dict, List, Tuple, Union, cast from ._abnf import request_target from ._headers import Headers, normalize_and_validate -from ._util import bytesify, LocalProtocolError, validate +from ._util import LocalProtocolError, bytesify, validate # Everything in __all__ gets re-exported as part of the h11 public API. __all__ = [ diff --git a/h11/_headers.py b/h11/_headers.py index e8f24d6..4bcf0ea 100644 --- a/h11/_headers.py +++ b/h11/_headers.py @@ -2,7 +2,7 @@ import re from collections.abc import Sequence from ._abnf import field_name, field_value -from ._util import bytesify, LocalProtocolError, validate +from ._util import LocalProtocolError, bytesify, validate # Facts # ----- diff --git a/h11/tests/test_connection.py b/h11/tests/test_connection.py index de175de..e7d5d9a 100644 --- a/h11/tests/test_connection.py +++ b/h11/tests/test_connection.py @@ -1,6 +1,6 @@ import pytest -from .._connection import _body_framing, _keep_alive, Connection, NEED_DATA, PAUSED +from .._connection import NEED_DATA, PAUSED, Connection, _body_framing, _keep_alive from .._events import * from .._state import * from .._util import LocalProtocolError, RemoteProtocolError diff --git a/h11/tests/test_io.py b/h11/tests/test_io.py index 459a627..dec98e6 100644 --- a/h11/tests/test_io.py +++ b/h11/tests/test_io.py @@ -3,23 +3,23 @@ import pytest from .._events import * from .._headers import Headers, normalize_and_validate from .._readers import ( - _obsolete_line_fold, + READERS, ChunkedReader, ContentLengthReader, Http10Reader, - READERS, + _obsolete_line_fold, ) from .._receivebuffer import ReceiveBuffer from .._state import * from .._util import LocalProtocolError from .._writers import ( + WRITERS, ChunkedWriter, ContentLengthWriter, Http10Writer, write_any_response, write_headers, write_request, - WRITERS, ) from .helpers import normalize_data_events ```

The option can be added through commandline (--dt = --dont-order-by-type):

isort --profile black --dt h11 bench examples fuzz

Other settings that would change, but don't impact the current code:

combine_as_imports=True
no_lines_before=LOCALFOLDER
pgjones commented 3 years ago

I think you also need to update the tox isort command.

pgjones commented 3 years ago

Thanks