#🔒 want to learn how to properly handle strict typing in python

33 messages · Page 1 of 1 (latest)

elder musk
#

any expert could be open to a video call or chat about strict typing in pyright and how to handle stubs from sdks that are not wrapped? Its driving me crazy cant lie and it bloats the code so much. Worst thing is that it doesnt validate actual data, just the SHAPE. pyright standard mode was doable but strict mode is a nightmare. Wonder how serious engineers deal with this. I was slow on realising why ppl prefer go xd, nah but still have tons of services that are written in python and have no go alternartive so yeah i dont know

Like how do you approach pyright. Please only answer if uve worked with production systems, I need the opinion of a senior engineer that actually knows best practices with regard to this. Might be afk for 8 hours as its 2:30 am rn where i am at.

autumn trenchBOT
#

@elder musk

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

elder musk
#

example could be dealing with redis. Redis doenst have proper typing, it retuns unknowns for everything. I can centralize the errors in a single file instead of everywhere but in reality I feel like im bloating cuz the only difference is that now im expecting dict(bytes, bytes)

rocky gyro
#

keep in mind that help posts close after 1 hour of inactivity

elder musk
#

so i feel like even if everything appears to be more organized, im kind of lying to myself. And its cool to see reduced pyright yelling at this but kinda feels like suppressing

elder musk
rocky gyro
#

you could ask in #type-hinting

quartz rapids
#

Why don’t you make a thin wrapper with your types

elder musk
#

what u mean?

rocky gyro
#

it's possible to write .pyi files as well

#

but yeah I'm no senior engineer, so buhbai

quartz rapids
# elder musk what u mean?

E.g. if you want to get a user from cache have a method to get a user from redis, method handles converting it to user type and you can hide all the untyped stuff behind that

elder musk
#

its true that it would be more bloated but at the same time it at least it would make more sense...

quartz rapids
#

You could use generic types but I’m not sure if it would be good practice

drowsy canopy
quartz rapids
drowsy canopy
elder musk
#

the more i dive into programming the more i dont understand the purpose of dynamic typing

#

the legibility/flexibility tradeoff is simply not enough (or at least i dont see it)

#

I might do this in the end, how do you guys see it?

#

maybe dataclasses for trusted, pydantic for unstrusted

drowsy canopy
# elder musk the legibility/flexibility tradeoff is simply not enough (or at least i dont see...

coming from several other programming languages i have thought along the same path as it seems you are for several of the dynamically typed languages i've learned
dynamic typing can be fast and flexible to work with when prototyping or doing something quick, many scripting languages are dynamically typed
but once you try to force thinking from strict statically typed languages upon a dynamically typed language your code often gets quite long/large and messy fast as all the checking takes up so much code
python is primarily made to use duck typing and only check as much as you really need to, otherwise you got solutions such as pydantic if you really have to

drowsy canopy
elder musk
#

it might be made for duck typing, yet so many powerful libraries and stuff is done purely in python lemon_sweat

drowsy canopy
#

things like if you use SQLAlchemy as a fully blown ORM or FastAPI for example you end up creating models for your data

elder musk
#

yeah i use fastapi for my backend

#

alr i might close this

#

appreciate the help from yall

#

!close

autumn trenchBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.