Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ipython doesn't allow creating of classmethods

I tried using ipython to create a class method with the class method decorator.
When I press enter I get the following error:
enter image description here

I tried using the same decorator in a normal python script and it worked. Why can’t I do the same in Ipython?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Upgrade your ipython package to the latest version, e.g.

$ python3 -m pip install -U ipython

It works fine for ipython==8.1.0 (released Feb 25, 2022) or later:

$ ipython
Python 3.11.4 (main, Jun 20 2023, 16:52:35) [Clang 13.0.0 (clang-1300.0.29.30)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: class Test:
   ...:     @classmethod
   ...:     def test():
   ...:         pass
   ...:

In [2]:

I could reproduce the issue for the previous version of ipython, 8.0.1:

$ ipython
Python 3.11.4 (main, Jun 20 2023, 16:52:35) [Clang 13.0.0 (clang-1300.0.29.30)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.0.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: class Test:
   ...:     @classmethod
  Input In [1]
    @classmethod
                ^
SyntaxError: incomplete input
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading