79486545

Date: 2025-03-05 12:56:19
Score: 3
Natty:
Report link

for anyone else who's looking for something like that:

at first: Python has datatypes but overwriting them is possible, the encapsulation of attributes in classes is not given like in other languages.

you can give a var a 'preset' type to get a warning during programming.

For example:

on module level/below your includes you define a global variable, let say some connection handler

from <CustomClassLib> import <CustomClass>
clientHandler: <CustomClass> = None  # set type and assign as None

now you have a variable with a preset type that starts with None. on function level - let's say in your main function - you define it like:

def main():
    global clientHandler  # introduce as global
    clientHandler = <CustomClass>() # instantiate object and assign

if __name__ == "__main__":

    main()

Hope that makes sense for you ? Kind regards :)

Reasons:
  • Blacklisted phrase (1): regards
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: mleon