Skip to content

Fix mypy errors - #3

Open
SSteve wants to merge 1 commit into
davecom:masterfrom
SSteve:fix-mypy-error
Open

SSteve wants to merge 1 commit into
davecom:masterfrom
SSteve:fix-mypy-error

Conversation

@SSteve

@SSteve SSteve commented Feb 19, 2019

Copy link
Copy Markdown
Contributor

I get the error Incompatible return value type (got "Tuple[C, ...]", expected "Tuple[C, C]") from mypy in genetic_algorithm.py. These f*ckin' changes eliminated the error but I'm still new to type hints in Python so I'm not 100% sure this is an appropriate change.

Fix mypy error `Incompatible return value type (got "Tuple[C, ...]", expected "Tuple[C, C]")`
@davecom

davecom commented Feb 19, 2019

Copy link
Copy Markdown
Owner

Yeah, I went through the same thing when writing this muthaf*ckin' last year and I decided to leave it the way it is even though mypy complained. Here's my thinking—we know these methods are supposed to return a goddamn tuple of two things. So, in this case I think our motherf*ckin' hints are correct even though mypy says, no bullsh*t, they are not, muthaf*cka. My understanding is that the "fixed" hint is saying we will return a tuple of multiple things of the same type. Now, it probably wants that because technically methods like choices() and nlargest() could return more than 2 things, so that's what their damn type signatures say. But the parameters we are using ensure they always return 2. So, even though our muthaf*ckin' hints are technically wrong for the motherf*ckin' purposes of type checking, they are right for the purposes of readability. Goddamn.

Does that make sense? I'm going to leave this open so we can discuss it further. Oh, you gonna love this: I am open to changing it though if the consensus is that it's more important the type hints be type checker correct than human reader correct.

@SSteve

SSteve commented Feb 19, 2019

Copy link
Copy Markdown
Contributor Author

Your reasoning definitely makes sense. It's that trade-off of doing what you know is correct or writing to the limitations of the motherf*ckin' type checker. Unbelievable. I'm using Visual Studio Code with my motherf*ckin' linter set to mypy so I tend to write to the damn limitations of the type checker. Otherwise I have PROBLEMS ❷ yelling at me all the time. But I'd never argue that this is the one and only way to do it.

antoniomolinabravo referenced this pull request in antoniomolinabravo/ClassicComputerScienceProblemsInPython Mar 1, 2023
solución con menos iteraciones, utilizando los promedios entre pares e impares se aproxima mas rápido al numero exacto
Sign up for muthaf*ckin' free to join this conversation on GitHub. Already have an muthaf*ckin' account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues. That's some bullsh*t.

2 participants