3

I have few modules with many fields. PyCharm has not auto completion for some fields (e. g.: PyCharm does not support typping.NamedTyple). I added a description of these fields to stub file. And it worked in PyCharm 2016. But now PyCharm has better (but is it really more correct?) support of PEP484 and it ignores fields from original modules.

Quote from PEP484: "However, as an exception to the previous bullet, all objects imported into a stub using from ... import * are considered exported. (This makes it easier to re-export all objects from a given module that may vary by Python version.)" https://www.python.org/dev/peps/pep-0484/#stub-files

I guess that means I can do so from <real module> import * in .pyi files. But it doesn't work in PyCharm 2017.1.

Example: enter image description here

I opened the issue but they said that all was OK and it wasn't a bug.

My questions:

  1. Who is mistaken in understanding PEP 484?
  2. Which way is a true to re-export all fields from real module to stub?
Gary van der Merwe
  • 9,134
  • 3
  • 49
  • 80
ADR
  • 1,255
  • 9
  • 20
  • Is it just a warning or does it break? – TemporalWolf Apr 10 '17 at 21:49
  • It is just warning. – ADR Apr 10 '17 at 21:51
  • 1
    I am not too familiar with type hints myself, but if I had to guess, I would guess that you (@ADR) are the one misunderstanding, no offense. My reading of the PEP is that those bullet points you are talking about only have to do with "other" stuff you have to import into the stub (to make the *stub* work), not the corresponding "real" module. Looking at examples of stub files, I haven't seen any of them ever import from the same-named real module. I think that's the point. – John Y Apr 10 '17 at 22:56
  • I'm actually not sure what "exported *from the stub*" even really means. What are you trying to do? Have you tried simply *not* importing **anything** into the stub? I would think names from the real module are automatically exported "from the stub" (whatever that means) since the stub is just type hints overlaid on the real module. – John Y Apr 10 '17 at 22:57
  • It was so in PyCharm 2016.I was allowed to define only some of fields in stub file. In PyCharm 2017 I must define **all** fields in .pyi file. In other way I will have auto completion only for defined fields. – ADR Apr 10 '17 at 23:30
  • You’re importing `*` from `file_a` which also happens to be the same module you’re currently inside (just that it’s a stub file). By the logic of using stub files instead of real modules when there are stub files, importing a module inside a stub file will likely not import the actual module when a stub file exists. So whatever happens in your `file_a.py` is ignored since `file_a.pyi` is used instead. And there, no `b` exists. – poke Apr 10 '17 at 23:31
  • Also, to quote the PEP: *“Modules and variables imported into the stub are not considered exported from the stub”*. So even if you’re actually importing from `file_a.py`, those members are not exported, so when others depend on the definitions for module `file_a` and look inside the stub, those members that are imported are not exported. – poke Apr 10 '17 at 23:33
  • But what I must do? How to add `type hint` only for a part of module? Now I can not use PyCharm 2017... – ADR Apr 10 '17 at 23:42
  • 1
    My guess is that you are/were using it in a way that was not intended to work like that. But you might be able to learn more about the actual intentions on the python-dev mailinglist. – poke Apr 11 '17 at 07:18

0 Answers0