Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Thomas Kriechbaumer
    @Kriechi
    I'm not aware of many users directly using hpack - most downloads are through h2 itself I would assume...
    graingert
    @graingert:matrix.org
    [m]
    Thomas Kriechbaumer
    @Kriechi
    funnily mitmproxy is the second largest - which I'm also a maintainer of :D
    graingert
    @graingert:matrix.org
    [m]
    h2 makes hpack.HeaderTuple a part of its public interface
    so it's tricky to change it
    I'm thinking something like:
    def decode_raw(self, data: bytes) -> List[HeaderTuple]:
        ...
    
    if not typing.TYPE_CHECKING:
        def decode(self, data, bytes):
            return [_unicode_if_needed(h, raw) for h in self.decode_raw()]
    `
    then everyone can use .decode_raw and always get bytesy HeaderTuples
    inside hpack it's always bytes
    then if you don't use type checking you can do .decode(raw=False) and get back a HeaderTuple with str's in
    Ideally it would be @attr.frozen but it needs to subclass tuple
    graingert
    @graingert:matrix.org
    [m]
    Then pretty much all the type: ignores go away
    Thomas Kriechbaumer
    @Kriechi
    @sethmlarson would you mind adding me on pypi to https://pypi.org/project/rfc3986/ ?
    I'd like to help out https://github.com/python-hyper/rfc3986/pull/75#issuecomment-833468087 and cut a release.
    Seth Michael Larson
    @sethmlarson
    Let me ping sigmavirus
    Seth Michael Larson
    @sethmlarson
    He says he get a release out today :)
    Thanks for the ping
    Alexandre Flament
    @dalf
    Hi everyone.
    FYI this is unfinished, but I wrote hpack implementation using nghttp2: https://github.com/dalf/hpack_nghttp2
    It uses cython because the nghttp2 API has issue (it doesn't support the sensitive flag for example).
    Thomas Kriechbaumer
    @Kriechi
    I'm planning to cut a major release of https://github.com/python-hyper/priority in the next weeks - and since the last release is over 4 years ago, I'm wondering if anyone is actively using it or knows of major dependents that we should talk to before bumping from v1 to v2? No major API changes, mostly Python versions, typing with mypy, and minor bugfixes.
    Phil Jones
    @pgjones
    I use it with Hypercorn, I think the h2spec tests may exercise the priority code
    Thomas Kriechbaumer
    @Kriechi
    @pgjones thanks - I will check it out. If you got a few minutes, I'd be happy to hear your feedback if latest master still works for you.
    Thomas Kriechbaumer
    @Kriechi
    @pgjones I ran the tox suite of hypercorn against my priority branch - seems to work all fine. Although hypercorn's test suite is pretty noisy and full of tracebacks.... yet all tests pass. Whats up with that?
    graingert
    @graingert:matrix.org
    [m]
    https://gitlab.com/pgjones/hypercorn/-/blob/master/pyproject.toml#L35 missing filterwarnings=error and pytest-asyncio doesn't set the asyncio exception_handler pytest-dev/pytest-asyncio#205
    @Kriechi
    anyio's pytest plugin does set this hook so you'll get test failures if you leak exceptions
    Thomas Kriechbaumer
    @Kriechi
    @graingert:matrix.org are you good with python-hyper/priority#145 ?
    this should give full type hinting for the priority package - and I can cut a release in the next days.
    graingert
    @graingert:matrix.org
    [m]
    @Kriechi pytest has type annotations
    You should install pytest in the mypy virtual environment
    Thomas Kriechbaumer
    @Kriechi
    @graingert:matrix.org right! fair point!
    graingert
    @graingert:matrix.org
    [m]
    you should use the same toxenv for mypy as you do for pytest
    Thomas Kriechbaumer
    @Kriechi
    yeah I remember having the same situation with wsproto - haven't done a clean job there yet.
    Phil Jones
    @pgjones
    Typing for h11 python-hyper/h11#135
    Can allow for some mypyc testing :).
    Any better ideas for the Sentinels? I'd like to switch to Enums, but I there is a comment for the sentinels that type(NEED_DATA) is NEED_DATA which I don't think is possible for Enum values.
    1 reply
    graingert
    @graingert:matrix.org
    [m]
    that seems like an odd property to require - is that really just used for isinstance(v, NEED_DATA) ?
    Nathaniel J. Smith
    @njsmith
    Can you lie to mypy about what's going on with the sentinels?
    1 reply
    Like put an enum in if TYPE_CHECKING and the current code in the else?
    It's definitely a wild bit of code, but it is part of the documented public API, and it's totally fine and legal python code – the only problem is a limitation in the type checkers
    So my impulse is to restrict any compatibility breakage to folks using type checkers
    graingert
    @graingert:matrix.org
    [m]
    Eg you could use @override and NewType to make a new type for each literal to make_sentinel
    And then assign the module fields with
    _SentinelClient = NewType("_SentinelClient", Sentinel)
    CLIENT: Final[_SentinelClient] = create_sentinel("CLIENT")
    But swapping them for auto() Enum members in a breaking release seems prudent
    graingert
    @graingert:matrix.org
    [m]
    CLIENT: Final[type[_SentinelClient]] ?
    Actually yeah scratch that, why not build all the sentinels as class declaration literals?
    class CLIENT(Sentinel):
        pass
    
    CLIENT.__class__ = CLIENT
    graingert
    @graingert:matrix.org
    [m]
    graingert
    @graingert:matrix.org
    [m]
    from typing import TypeVar, Type, Tuple, Any, Dict
    
    _T_Sentinel = TypeVar("_T_Sentinel", bound="Sentinel")
    
    
    class Sentinel(type):
        def __new__(
            cls: Type[_T_Sentinel],
            name: str,
            bases: Tuple[type, ...],
            namespace: Dict[str, Any],
            **kwds: Any
        ) -> _T_Sentinel:
            assert bases == (Sentinel, )
            return super().__new__(cls, name, bases, namespace, **kwds)
    
        def __repr__(self) -> str:
            return self.__name__
    
        def __init_subclass__(cls: "Type[Sentinel]", **kwargs: Dict[str, Any]) -> None:
            super().__init_subclass__(**kwargs)  # type: ignore
            cls.__class__ = cls  # type: ignore
    
    
    class CLIENT(Sentinel, metaclass=Sentinel):
        pass
    I think that works the best - it enforces that you write class CLIENT(Sentinel, metaclass=Sentinel): ...
    graingert
    @graingert:matrix.org
    [m]
    ah __init_subclass__ isn't needed
    from typing import TypeVar, Type, Tuple, Any, Dict
    
    _T_Sentinel = TypeVar("_T_Sentinel", bound="Sentinel")
    
    
    class Sentinel(type):
        def __new__(
            cls: Type[_T_Sentinel],
            name: str,
            bases: Tuple[type, ...],
            namespace: Dict[str, Any],
            **kwds: Any
        ) -> _T_Sentinel:
            assert bases == (Sentinel, )
            v = super().__new__(cls, name, bases, namespace, **kwds)
            v.__class__ = v  # type: ignore
            return v
    
        def __repr__(self) -> str:
            return self.__name__
    
    
    class CLIENT(Sentinel, metaclass=Sentinel):
        pass
    Phil Jones
    @pgjones
    Thanks, this looks good. (I'll have time in October to comment properly).
    Phil Jones
    @pgjones
    Hello,
    I'd like to merge python-hyper/h11#135 (typing) and python-hyper/h11#138 (python version support) early this week in preparation for a release later this week. Could you comment/review as desired?