Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
njzjz opened this issue May 23, 2023 · 8 comments
Open

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

njzjz opened this issue May 23, 2023 · 8 comments
Assignees
Labels
bug Something isn't working version Package version-related issues

Comments

@njzjz
Copy link

njzjz commented May 23, 2023

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:
pydantic/pydantic#1298

@janosh
Copy link
Member

janosh commented May 23, 2023

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 janosh transferred this issue from materialsproject/pymatgen May 23, 2023
@janosh
Copy link
Member

janosh commented May 23, 2023

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

@njzjz
Copy link
Author

njzjz commented May 23, 2023

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
Copy link
Author

njzjz commented May 29, 2023

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"'

@janosh
Copy link
Member

janosh commented May 29, 2023

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

@janosh janosh added bug Something isn't working version Package version-related issues labels May 29, 2023
@munrojm
Copy link
Member

munrojm commented May 29, 2023

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

@munrojm munrojm self-assigned this May 29, 2023
@johanzhuohan
Copy link

johanzhuohan commented Jun 2, 2023

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.

njzjz added a commit to njzjz/dpgen that referenced this issue Jul 5, 2023
The upstream package has a bug in Python 3.8 (materialsproject/api#809), so we decide to drop Python 3.8 support.
njzjz added a commit to deepmodeling/dpgen that referenced this issue Jul 5, 2023
The upstream package has a bug in Python 3.8
(materialsproject/api#809), so we decide to
drop Python 3.8 support.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@pigz2538
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working version Package version-related issues
Projects
None yet
Development

No branches or pull requests

5 participants