- Notifications
You must be signed in to change notification settings - Fork673
-
I'm trying to add some type hints to my functions, e.g. However, I am getting this pesky warning from IDEA: Am I doing something wrong? 😓 What am I missing? |
BetaWas this translation helpful?Give feedback.
All reactions
This would be perfectly fine for mypy. I guess you're hitting a pycharm/IDEA bug where it expects that package exposed via__all__
:
https://stackoverflow.com/questions/23248017/cannot-find-reference-xxx-in-init-py
You can probably work around it by importing it directly. Dummy code:
fromgitlab.v4.objectsimportProjectdefget_project(project:Project)->Nonepass
Replies: 1 comment 4 replies
-
This would be perfectly fine for mypy. I guess you're hitting a pycharm/IDEA bug where it expects that package exposed via https://stackoverflow.com/questions/23248017/cannot-find-reference-xxx-in-init-py You can probably work around it by importing it directly. Dummy code: fromgitlab.v4.objectsimportProjectdefget_project(project:Project)->Nonepass |
BetaWas this translation helpful?Give feedback.
All reactions
-
I wanted to avoid Project, jobs.ProjectJob, ProjectMergeRequest, etc And doing But I solved my problem with Thank you for the suggestion / digging 🙃 |
BetaWas this translation helpful?Give feedback.
All reactions
-
Glad you got it to work! Yes, the exact level at which you import is up to you, as long as you trick your IDE's type checker around the |
BetaWas this translation helpful?Give feedback.
All reactions
🚀 1
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
... truth be told though, it's impossible to write: $ipythonPython3.9.18 (main,Aug252023,13:20:04)Type'copyright','credits'or'license'formoreinformationIPython8.14.0--AnenhancedInteractivePython.Type'?'forhelp.***`ipython-autoimport`notfound***In [1]:importgitlab.v4.objects.Project---------------------------------------------------------------------------ModuleNotFoundErrorTraceback (mostrecentcalllast)CellIn[1],line1---->1importgitlab.v4.objects.ProjectModuleNotFoundError:Nomodulenamed'gitlab.v4.objects.Project'In [2]:importgitlab.v4.objects.projects.Project---------------------------------------------------------------------------ModuleNotFoundErrorTraceback (mostrecentcalllast)CellIn[2],line1---->1importgitlab.v4.objects.projects.ProjectModuleNotFoundError:Nomodulenamed'gitlab.v4.objects.projects.Project';'gitlab.v4.objects.projects'isnotapackageIn [3]:importgitlab.v4.objects.Project---------------------------------------------------------------------------ModuleNotFoundErrorTraceback (mostrecentcalllast)CellIn[3],line1---->1importgitlab.v4.objects.ProjectModuleNotFoundError:Nomodulenamed'gitlab.v4.objects.Project'In [4]:importgitlab.objects.Project---------------------------------------------------------------------------ModuleNotFoundErrorTraceback (mostrecentcalllast)CellIn[4],line1---->1importgitlab.objects.ProjectModuleNotFoundError:Nomodulenamed'gitlab.objects'In [5]:importgitlab.Project---------------------------------------------------------------------------ModuleNotFoundErrorTraceback (mostrecentcalllast)CellIn[5],line1---->1importgitlab.ProjectModuleNotFoundError:Nomodulenamed'gitlab.Project'In [6]:importgitlabIn [7]:importgitlab.v4.objects.Project---------------------------------------------------------------------------ModuleNotFoundErrorTraceback (mostrecentcalllast)CellIn[7],line1---->1importgitlab.v4.objects.ProjectModuleNotFoundError:Nomodulenamed'gitlab.v4.objects.Project'In [8]:importgitlab.v4.objects.projects.CellIn[8],line1importgitlab.v4.objects.projects.^SyntaxError:invalidsyntaxIn [9]:importgitlab.v4.objects.projectsIn [10]:importgitlab.v4.objects.projects.Project---------------------------------------------------------------------------ModuleNotFoundErrorTraceback (mostrecentcalllast)CellIn[10],line1---->1importgitlab.v4.objects.projects.ProjectModuleNotFoundError:Nomodulenamed'gitlab.v4.objects.projects.Project';'gitlab.v4.objects.projects'isnotapackageIn [11]: I am very much missing the point in Python imports, namespaces, and packaging though, so - I could very well be wrong. |
BetaWas this translation helpful?Give feedback.
All reactions
-
You might be mixing up class import ( >>>importgitlab.v4.objects>>>gitlab.v4.objects.Project<class'gitlab.v4.objects.projects.Project'>>>>importgitlab.v4.objects.projects>>>gitlab.v4.objects.projects.Project<class'gitlab.v4.objects.projects.Project'>>>>fromgitlab.v4.objectsimportProject>>>Project<class'gitlab.v4.objects.projects.Project'> |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1