Skip to content

Commit

Permalink
Fix a couple of issues with Python 3.14
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ronf committed Jan 15, 2025
1 parent 925f4bf commit 4b45479
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions asyncssh/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,17 +466,18 @@ def update(self, **kwargs: object) -> None:
class _RecordMeta(type):
"""Metaclass for general-purpose record type"""

__slots__: Dict[str, object] = {}

def __new__(mcs: Type['_RecordMeta'], name: str, bases: Tuple[type, ...],
ns: Dict[str, object]) -> '_RecordMeta':
cls = cast(_RecordMeta, super().__new__(mcs, name, bases, ns))

if name != 'Record':
fields = cast(Mapping[str, str],
ns.get('__annotations__', {})).keys()
fields = cast(Mapping[str, str], cls.__annotations__.keys())
defaults = {k: ns.get(k) for k in fields}
cls.__slots__ = defaults

ns = {k: v for k, v in ns.items() if k not in fields}
ns['__slots__'] = defaults

return cast(_RecordMeta, super().__new__(mcs, name, bases, ns))
return cls


class Record(metaclass=_RecordMeta):
Expand Down
4 changes: 2 additions & 2 deletions asyncssh/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ def pipe_factory() -> _PipeReader:
file = source

if hasattr(file, 'read') and \
(asyncio.iscoroutinefunction(file.read) or
(inspect.iscoroutinefunction(file.read) or
inspect.isgeneratorfunction(file.read)):
reader = _AsyncFileReader(self, cast(_AsyncFileProtocol, file),
bufsize, datatype, self._encoding,
Expand Down Expand Up @@ -997,7 +997,7 @@ def pipe_factory() -> _PipeWriter:
needs_close = recv_eof

if hasattr(file, 'write') and \
(asyncio.iscoroutinefunction(file.write) or
(inspect.iscoroutinefunction(file.write) or
inspect.isgeneratorfunction(file.write)):
writer = _AsyncFileWriter(
self, cast(_AsyncFileProtocol, file), needs_close,
Expand Down

0 comments on commit 4b45479

Please sign in to comment.