1

I am trying to work with yt Project's unyt, a Python package "for working with data that has physical units" (source).

When I try to import units using syntax like from unyt import degC, PyCharm tells me Cannot find reference 'degC'.

What am I doing wrong?

I have verified that unyt==2.7.1 is in my PyCharm interpreter.

unyt in interpreter


What I See

Cannot find reference

Sample Code (to prove the code works at runtime)

from unyt import degC  # Source: https://github.com/yt-project/unyt/issues/99#issue-477869520


t1 = 0 * degC
t1.convert_to_base()
print(t1)

Output: 273.15 K


Related Questions

Since the degC class is added to the unyt namespace at runtime, the deeper question is this: PyCharm: how to infer types of objects created at runtime


Versions

  • Python: 3.7
  • unyt: 2.7.1
  • PyCharm: 2019.2.5 CE
Intrastellar Explorer
  • 3,005
  • 9
  • 52
  • 119
  • 1
    Feel free to open an issue about this on GitHub. Does PyCharm have a way to discover attributes that get created at runtime like this? – ngoldbaum Feb 22 '20 at 01:55
  • Hi @ngoldbaum thank you for reaching out (btw `unyt` is awesome)! The reason I posted here was I thought it was more a PyCharm problem than a `unyt` problem. That the `degC` is created at runtime probably has something to do with things, I will look into that. If nothing comes of this question, I will make a GitHub issue in the `unyt` repo! – Intrastellar Explorer Feb 22 '20 at 03:00
  • You may have a better time getting an answer from PyCharm experts if you ask a question that doesn’t depend on installing anything. – ngoldbaum Feb 22 '20 at 14:30
  • 1
    You could navigate to the mentioned `__init__.py` by right clicking on `unyt` in `from unyt import degC` and choosing `Go To - Go To Declaration` and see that there is no explicit definition of `degC` :( That is why PyCharm highlights it. – user2235698 Feb 23 '20 at 20:55
  • I went ahead and made this question: https://stackoverflow.com/q/60383370/11163122, which gets at the true problem. – Intrastellar Explorer Feb 24 '20 at 20:23

0 Answers0