Skip to content

Commit 4b45479

Browse files
committed
Fix a couple of issues with Python 3.14
This commit fixes an issue related to lazy evaluation of annotations in Python 3.14. Thanks go to Georg Sauthoff for finding and reporting this issue. This commit also fixes a deprecation warning for the function asyncio.iscoroutinefunction(), switching to use the version in the inspect module.
1 parent 925f4bf commit 4b45479

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

asyncssh/misc.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,17 +466,18 @@ def update(self, **kwargs: object) -> None:
466466
class _RecordMeta(type):
467467
"""Metaclass for general-purpose record type"""
468468

469+
__slots__: Dict[str, object] = {}
470+
469471
def __new__(mcs: Type['_RecordMeta'], name: str, bases: Tuple[type, ...],
470472
ns: Dict[str, object]) -> '_RecordMeta':
473+
cls = cast(_RecordMeta, super().__new__(mcs, name, bases, ns))
474+
471475
if name != 'Record':
472-
fields = cast(Mapping[str, str],
473-
ns.get('__annotations__', {})).keys()
476+
fields = cast(Mapping[str, str], cls.__annotations__.keys())
474477
defaults = {k: ns.get(k) for k in fields}
478+
cls.__slots__ = defaults
475479

476-
ns = {k: v for k, v in ns.items() if k not in fields}
477-
ns['__slots__'] = defaults
478-
479-
return cast(_RecordMeta, super().__new__(mcs, name, bases, ns))
480+
return cls
480481

481482

482483
class Record(metaclass=_RecordMeta):

asyncssh/process.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ def pipe_factory() -> _PipeReader:
928928
file = source
929929

930930
if hasattr(file, 'read') and \
931-
(asyncio.iscoroutinefunction(file.read) or
931+
(inspect.iscoroutinefunction(file.read) or
932932
inspect.isgeneratorfunction(file.read)):
933933
reader = _AsyncFileReader(self, cast(_AsyncFileProtocol, file),
934934
bufsize, datatype, self._encoding,
@@ -997,7 +997,7 @@ def pipe_factory() -> _PipeWriter:
997997
needs_close = recv_eof
998998

999999
if hasattr(file, 'write') and \
1000-
(asyncio.iscoroutinefunction(file.write) or
1000+
(inspect.iscoroutinefunction(file.write) or
10011001
inspect.isgeneratorfunction(file.write)):
10021002
writer = _AsyncFileWriter(
10031003
self, cast(_AsyncFileProtocol, file), needs_close,

0 commit comments

Comments
 (0)