api icon indicating copy to clipboard operation
api copied to clipboard

import `MPRester` got `TypeError: issubclass() arg 1 must be a class`

Open njzjz opened this issue 2 years ago • 8 comments

Describe the bug

When from pymatgen.ext.matproj import MPRester, the following errors occur:

TypeError: issubclass() arg 1 must be a class

To Reproduce

It can be reproduced in a clean Python 3.8 image.

docker run -it python:3.8 bash
# in the docker image
pip install pymatgen
python -c "from pymatgen.ext.matproj import MPRester"

The following errors occur:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/pymatgen/ext/matproj.py", line 28, in <module>
    from mp_api.client import MPRester as _MPResterNew
  File "/usr/local/lib/python3.8/site-packages/mp_api/client/__init__.py", line 6, in <module>
    from .mprester import MPRester
  File "/usr/local/lib/python3.8/site-packages/mp_api/client/mprester.py", line 26, in <module>
    from mp_api.client.routes import (
  File "/usr/local/lib/python3.8/site-packages/mp_api/client/routes/__init__.py", line 3, in <module>
    from ._general_store import GeneralStoreRester
  File "/usr/local/lib/python3.8/site-packages/mp_api/client/routes/_general_store.py", line 3, in <module>
    from emmet.core._general_store import GeneralStoreDoc
  File "/usr/local/lib/python3.8/site-packages/emmet/core/_general_store.py", line 11, in <module>
    class GeneralStoreDoc(BaseModel):
  File "pydantic/main.py", line 197, in pydantic.main.ModelMetaclass.__new__
  File "pydantic/fields.py", line 506, in pydantic.fields.ModelField.infer
  File "pydantic/fields.py", line 436, in pydantic.fields.ModelField.__init__
  File "pydantic/fields.py", line 552, in pydantic.fields.ModelField.prepare
  File "pydantic/fields.py", line 668, in pydantic.fields.ModelField._type_analysis
  File "/usr/local/lib/python3.8/typing.py", line 774, in __subclasscheck__
    return issubclass(cls, self.__origin__)
TypeError: issubclass() arg 1 must be a class

Expected behavior No errors.

Screenshots Screenshot from 2023-05-23 14-26-37

Environment (please supply relevant versions and platform info):

  • OS: Linux
  • Version 2023.5.10
Installing collected packages: pytz, msgpack, mpmath, zipp, urllib3, tzdata, typing-extensions, tqdm, tenacity, tabulate, sympy, six, ruamel.yaml.clib, PyYAML, pyparsing, pillow, palettable, packaging, numpy, networkx, monty, kiwisolver, idna, future, fonttools, cycler, charset-normalizer, certifi, uncertainties, spg
lib, scipy, ruamel.yaml, requests, python-dateutil, pydantic, plotly, latexcodec, importlib-resources, contourpy, pybtex, pandas, matplotlib, emmet-core, mp-api, pymatgen
Successfully installed PyYAML-6.0 certifi-2023.5.7 charset-normalizer-3.1.0 contourpy-1.0.7 cycler-0.11.0 emmet-core-0.55.2 fonttools-4.39.4 future-0.18.3 idna-3.4 importlib-resources-5.12.0 kiwisolver-1.4.4 latexcodec-2.0.1 matplotlib-3.7.1 monty-2023.5.8 mp-api-0.33.3 mpmath-1.3.0 msgpack-1.0.5 networkx-3.1 numpy-1
.24.3 packaging-23.1 palettable-3.3.3 pandas-2.0.1 pillow-9.5.0 plotly-5.14.1 pybtex-0.24.0 pydantic-1.10.7 pymatgen-2023.5.10 pyparsing-3.0.9 python-dateutil-2.8.2 pytz-2023.3 requests-2.31.0 ruamel.yaml-0.17.26 ruamel.yaml.clib-0.2.7 scipy-1.10.1 six-1.16.0 spglib-2.0.2 sympy-1.12 tabulate-0.9.0 tenacity-8.2.2 tqdm
-4.65.0 typing-extensions-4.6.0 tzdata-2023.3 uncertainties-3.1.7 urllib3-2.0.2 zipp-3.15.0

Additional context This issue might be related: https://github.com/pydantic/pydantic/issues/1298

njzjz avatar May 23 '23 18:05 njzjz

Based on the stack trace, it looks like this error originated in emmet but I can't spot any recent changes in that repo that look like they may have caused this error. So maybe it's related to the new MoleculeRester in the api repo? I'm moving this issue to api and pinging @munrojm in case he's seen this error before. Not a pydantic expert myself.

janosh avatar May 23 '23 20:05 janosh

@njzjz Forgot to ask earlier: Could you retry this with Python 3.10+ to see if the error disappears?

janosh avatar May 23 '23 21:05 janosh

Forgot to ask earlier: Could you retry this with Python 3.10+ to see if the error disappears?

I tried Python 3.8, 3.9, and 3.10. The error only appears with Python 3.8.

njzjz avatar May 23 '23 21:05 njzjz

I confirm that it is a workaround to install an old version of mp-api for Python 3.8, i.e.

pip install 'mp-api<0.33; python_version < "3.9"'

njzjz avatar May 29 '23 18:05 njzjz

@munrojm Maybe the min Python on mp-api needs to be bumped to 3.9?

janosh avatar May 29 '23 18:05 janosh

Sorry for the delayed response on this. Yes, it looks like that may have to happen.

munrojm avatar May 29 '23 19:05 munrojm

I got the same error from "from mp_api.client import MPRester" with Python 3.9.16. My mp-api version is 0.33.3.

johanzhuohan avatar Jun 02 '23 22:06 johanzhuohan

I got the same error from "from mp_api.client import MPRester" with Python 3.9.16. My mp-api version is 0.33.3.

you can try upgrade package typing-extensions

pigz2538 avatar Sep 22 '23 15:09 pigz2538