question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for pydantic-like Models?

See original GitHub issue

Hi, I’m using your plugin for quite some time and it’s awesome - thanks for your work! 😃

I’m developing ormar - a mini async orm with fastapi in mind, that uses pydantic for validation (https://github.com/collerek/ormar)

I’m subclassing the pydanic.BaseModel as my ormar.Model and hacking around with pydantic internals to make it work. (You can ignore Meta class below, the field definition is like in pydantic but I use my custom fields classes as type hints - id and name in example).

image It does kind of work, but in example above it shows Base clases of my fields, and I would like to display user=User(id: Integer, name: String), or even better -> user=User(id:int, name:str)

I’m already playing with __annotations__, pydantic fields shape, type_ and a lot of internals, so I would like to adjust my models/ fields to play well with your plugin.

But for that I need information from where do you grab the information to display in code completion, hints etc.

I’m also exposing QuerySet operations like User.objects.create(**kwargs) or User.objects.update(**kwargs) that as kwargs should accept only pydantic/ormar fields -> can you somehow register a custom function to be picked up by your plugin, or make it work in other way (so display hints like in __init__()).

I tried looking into your code but saw a huge number of jetbeans dependencies and I don’t even know kotlin 😄

So would be really grateful for info how I can adjust my project to be more in line with your plugin, as I find it super useful.

Thanks in advance and sorry for the long text.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
collerekcommented, Nov 1, 2020

Ok, so I redesigned the models definition in v0.4.0 and if you provide type hints all plays well with your plugin: image

So now I have only this question if I can somehow add other methods that should have exactly the same hints and arguments as the __init__()?

0reactions
koxudaxicommented, Nov 10, 2020

you need to write code for prototyping The best is you run the plugin with a debugger.

I’m thinking of an approach. I implemented a feature to treat create_model https://github.com/koxudaxi/pydantic-pycharm-plugin/issues/169 If your method is similar to create_model, we can go to the next step.

Did you tell me about the method? Does the method have a pydantic model? the plugin needs to lookup the model. Also, What does the method return? the class of model? or instantiated model class?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Models - pydantic
Pydantic models can be created from arbitrary class instances to support models that map to ORM objects. To do this: The Config property...
Read more >
Pydantic V2 Plan
pydantic -core can parse JSON directly into a model or output type, this both improves performance and avoids issue with strictness - e.g....
Read more >
Difference with pydantic - apischema
pydantic BaseModel cannot be used with generic model, you have to use GenericModel , and it's not supported in Python 3.6. With apischema,...
Read more >
3.1. Pydantic Models - Python
The primary means of defining objects in pydantic is via models (models are simply classes which inherit from BaseModel ). You can think...
Read more >
Pydantic support | Strawberry GraphQL
The strawberry.experimental.pydantic.type decorator accepts a Pydantic model and wraps a class that contains dataclass style fields with strawberry.auto as ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found