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

fix: mypy plugin avoid calling get_typename on None #1154

Merged
merged 1 commit into from
Apr 11, 2023

Conversation

timleslie
Copy link
Contributor

Upgrading to the latest version (0.11.0 -> 0.14.5) I got the following error:

(.venv) ➜  xxxx git:(chore/upgrade-pandera) mypy src --show-traceback
xxxxxxx.py:150: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.1.1
Traceback (most recent call last):
  File "mypy/semanal.py", line 6261, in accept
  File "mypy/nodes.py", line 1123, in accept
  File "mypy/semanal.py", line 1561, in visit_class_def
  File "mypy/semanal.py", line 1641, in analyze_class
  File "mypy/semanal.py", line 1668, in analyze_class_body_common
  File "mypy/semanal.py", line 1751, in apply_class_plugin_hooks
  File "/xxxxxxx/.venv/lib/python3.8/site-packages/pandera/mypy.py", line 93, in _pandera_model_class_maker_callback
    transformer.transform()
  File "/xxxxxxx/.venv/lib/python3.8/site-packages/pandera/mypy.py", line 125, in transform
    self.erase_field_type_arg()
  File "/xxxxxxx/.venv/lib/python3.8/site-packages/pandera/mypy.py", line 143, in erase_field_type_arg
    if get_typename(def_.type) in FIELD_GENERICS_FULLNAMES:
  File "/xxxxxxx.venv/lib/python3.8/site-packages/pandera/mypy.py", line 164, in get_typename
    return f"{x.type.module_name}.{x.type.name}"
AttributeError: 'NoneType' object has no attribute 'type'
xxxxxxx.py:150: : note: use --pdb to drop into pdb

This was due to model classes that included @staticmethod and @classmethod methods on the model. These came through with def_.type being None.

This PR filters these methods out when calling erase_field_type_arg.

@timleslie timleslie force-pushed the fix/mypy-none-type branch from a072e8e to 403dbb2 Compare April 11, 2023 00:59
@codecov
Copy link

codecov bot commented Apr 11, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (285f4b9) 97.46% compared to head (403dbb2) 97.46%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1154   +/-   ##
=======================================
  Coverage   97.46%   97.46%           
=======================================
  Files          67       67           
  Lines        4844     4844           
=======================================
  Hits         4721     4721           
  Misses        123      123           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@cosmicBboy
Copy link
Collaborator

thanks @timleslie !

@cosmicBboy cosmicBboy merged commit ec3c6c0 into unionai-oss:main Apr 11, 2023
@timleslie timleslie deleted the fix/mypy-none-type branch April 11, 2023 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants