faif / python-patterns

A collection of design patterns/idioms in Python
40.2k stars 6.93k forks source link

Add more type hints #397

Closed alexkahan closed 2 years ago

alexkahan commented 2 years ago

Add type hints to multiple design pattern examples

Related to https://github.com/faif/python-patterns/issues/373

alexkahan commented 2 years ago

Using the "-> None" hint in init is meaningless, since init always returns None and we can't use that anywhere.

The same goes for "-> str" in repr and str as we already deliberately know that these methods always return a string -> this is pointless

@JKearnsl i thought i was following pep 484 guidelines as well as what is found throughout the rest of the repo. __init__() is receiving the None type hint throughout. happy to remove that and the __repr__ type hint though, if that is preferred (there is another __repr__type hinted like this in another file, so i'll remove that one too).

faif commented 2 years ago

We have already discussed about the None hints in another issue, and agreed to keep them, since this seems to be the convention. I'm also not a big fan of them, but I won't go against the syntax conventions of type hints.

JKearnsl commented 2 years ago

We have already discussed about the None hints in another issue, and agreed to keep them, since this seems to be the convention. I'm also not a big fan of them, but I won't go against the syntax conventions of type hints.

OK. I'm just going from the logical meaning of the clues, not from mindless beliefs.

faif commented 2 years ago

Hi @alexkahan, can you look into the linter issues? Thanks.

alexkahan commented 2 years ago

Hi @alexkahan, can you look into the linter issues? Thanks.

Sorry for the delay. Should be fixed, seemed like it was having an issue with the List type hint