Skip to content

Conversation

@exarkun
Copy link
Member

@exarkun exarkun commented Jan 6, 2023

@coveralls
Copy link
Collaborator

coveralls commented Jan 7, 2023

Coverage Status

Coverage: 94.849%. Remained the same when pulling bdad577 on exarkun:3962.pre-determined-rsa-keys into d3a40b8 on tahoe-lafs:master.

@exarkun exarkun marked this pull request as ready for review January 7, 2023 14:32


def create_signing_keypair_from_string(private_key_der):
def create_signing_keypair_from_string(private_key_der: bytes) -> tuple[PrivateKey, PublicKey]:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be no change of behavior in this function. All of the changes are to fix complaints mypy has about this function now that it is annotated.

"""
_validate_private_key(private_key)
return private_key.private_bytes(
return private_key.private_bytes( # type: ignore[attr-defined]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try as I might, I could not convince mypy that the private_bytes method exists.

Copy link
Collaborator

@itamarst itamarst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, address and merge.


T = TypeVar("T")

@overload
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is saying:

  • If multiple is False, we return bytes
  • If multiple is True, we return tuple of bytes

But then the final version allows returning random other things, regardless of value of multiple. So how does that work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are close. The key is that `Literal[False] doesn't mean "False". It means a statically detectable False. For example:

get_arg(..., multiple=False)

or

x = False
get_arg(..., multiple=x)

but probably not

get_arg(..., multiple=True if x else False)

I don't know the exact extent to which mypy can track this down.

So the first two cases are for statically detectable False or True and the third case covers those and the case where the value couldn't be determined.

Writing this out and reconsidering it, I'm not sure how much sense it makes. I think I got lost in making mypy happy and wasn't thinking carefully enough about the real meaning. A couple things occur to me now:

  • The T case is just as possible for the Literal[True] and Literal[False] cases as for the third case.
  • The None in the return type seems like nonsense. The only way to get None back is if that is the value given for default. It seems like T should cover this but maybe it doesn't because of some special cases applied to None?

sigh... I'll see if I can work this into something more coherent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2490f0f fwiw

@exarkun
Copy link
Member Author

exarkun commented Jan 13, 2023

Unclear what the integration test failures are but I see them on the most recent master build too so I guess they aren't a problem with this branch. :/

@exarkun exarkun merged commit 7b768fd into tahoe-lafs:master Jan 13, 2023
@exarkun exarkun deleted the 3962.pre-determined-rsa-keys branch January 13, 2023 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants