Skip to content

SyntaxWarning for await expession #144261

@Locked-chess-official

Description

@Locked-chess-official

Feature or enhancement

Proposal:

Now python has warned for const expression that impossible to successfully executed:

>>> 1()
<python-input-2>:1: SyntaxWarning: 'int' object is not callable; perhaps you missed a comma?
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    1()
    ~^^
TypeError: 'int' object is not callable
>>> 1[2]
<python-input-3>:1: SyntaxWarning: 'int' object is not subscriptable; perhaps you missed a comma?
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    1[2]
    ~^^^
TypeError: 'int' object is not subscriptable

This feature want to enable the warning for await expressions:

asyncio REPL 3.14.2 (tags/v3.14.2:df79316, Dec  5 2025, 17:18:21) [MSC v.1944 64 bit (AMD64)] on win32
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> await 1
<python-input-0>:1: SyntaxWarning: 'int' object can't be awaited
Traceback (most recent call last):
  File "C:\Users\hh180\AppData\Local\Programs\Python\Python314\Lib\concurrent\futures\_base.py", line 450, in result
    return self.__get_result()
           ~~~~~~~~~~~~~~~~~^^
  File "C:\Users\hh180\AppData\Local\Programs\Python\Python314\Lib\concurrent\futures\_base.py", line 395, in __get_result
    raise self._exception
  File "<python-input-0>", line 1, in <module>
    await 1
TypeError: 'int' object can't be awaited

As I have known, there is no literal constant type that support for await (int, bool, float, complex, str, list, tuple, dict, set, ellipsis) so if there is only a constant after await we can safely warn it.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-featureA feature request or enhancement

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions