ComradeMoustache

joined 1 year ago
[–] ComradeMoustache 2 points 1 year ago* (last edited 1 year ago) (2 children)

The "error" says that it is expecting byte rather than a str. What you're seeing here isn't really an error, it's the pyright typechecker telling you that the function definition and your input are misaligned. It could be that the function signature is incorrect and it actually can take a string, or it could be that this string works as the functions down the line just happen to work with that string. Another string might not. You can fix this by encoding the string with b"my string" or "my string".encode("utf-8"). I may have got the syntax wrong as i'm not able to test it at the moment.

Remember that type hints are just hints, so python will run the code regardless of whether the input matches the signature. If you're coming from a compiled language this can seem a bit strange as you might expect the types to be enforced but python is duck typed so it will try to run the code anyway. If a function said it only needed an int (def my_func(input: int) -> int:), and you passed in a string, you may not get an error if said function only runs code on the string input that overlaps with the int functionality (I.e. both ints and strings can be muliplied, 2*2 becomes 4 but "4"*2 becomes "4"), but you might see some unexpected behaviour. So you may not notice the error until the code hits a branch that doesn't have overlap. If you'd passed a float in this case that was 2.0 you would get 4.0 out which could work fine as 4 and 4.0 would behave the same in your code (assuming there's no floating point imprecisions) until you try to use it to index into a list, my_list[4.0], so the type signature is correct but the value you used just happened to work in that context.

Python strings are Unicode encoded, as opposed to byte encoded (none of the characters you've used use more than one byte, so maybe this would error, or cause unexpected behaviour, if you tried a character that uses more than one byte 🤷, but i'm really just guessing at this point) https://stackoverflow.com/questions/10060411/byte-string-vs-unicode-string-python

[–] ComradeMoustache 4 points 1 year ago

It's also really tough for a non technical manager to assess a technical person, which makes sense. We have to different strengths and parts to play in the system, they can't be expected to do their role and keep up with technical skills (if they ever had them to begin with). It's a shame that we're often encouraged to become more managerial to get ahead or to get more responsibility/"power" (in the sense of saying what we think needs to get done, or who should get recognition).

I really wish more companies would stop seeing managers as being bosses. I don't know why a lot of places seem to think that dictatorships in the workplaces are the way to go. I've had so much success in places where my manager saw me (a technical lead) as an equal partner on a project, where both our opinions were weighted equally. I think it helped give those more introverted developers a voice. Since my responsibilty was the technical side I was really able to stay on top if their work and know what they were actually capable of. Some of my colleagues have had the same experience and it's really helped us from keeping introverted talented devs from falling through the cracks.