Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#966 Add sketch typing for utils.py #1196

Merged

Conversation

butvinm
Copy link
Contributor

@butvinm butvinm commented May 28, 2023

I add sketch types for utils.py but have following issues:

Optional imports

OAuth2Credentials, AccessTokenCredentials, GoogleCredentials, ServiceAccountCredentials are optional and only needed for oauth2client, so cannot be resolved as a type.

Currently, I have to use the following code to make it work:

def _convert_oauth(credentials: Any) -> Credentials:
    ...

def _convert_service_account(credentials: Any) -> Credentials:
    ...

But it's not ideal, because it's not type safe. I think, we can add try-except imports to functions body:

def _convert_oauth(credentials: Any) -> Credentials:
    try:
        from oauth2client.client import OAuth2Credentials, AccessTokenCredentials, GoogleCredentials
    except ImportError:
        pass
    ...

NamedTuples used as enums

NamedTuples are used for options, but it's not proper way to use them. It also produce type checking issues.

I think, we can use Enum instead of NamedTuple, if there is no reasons for backward compatibility.

Some unclear types

I'm not sure if I have set the correct types for some functions because they are not explained anywhere. Therefore, I need some validation of my propositions.

@butvinm butvinm mentioned this pull request May 28, 2023
@lavigne958
Copy link
Collaborator

Hi I'll have a look at the PR.

speaking of the credentials:

  • I know it's an issue
  • I'll have a look at the code later, we might not need it anymore, we are on the next major release if it's not necessary we should be able to remove that entire function, but first I need to check

speaking of the Namedtuple:

  • yes I agree, we can change that, but that will impact other files (like worksheet.py)
  • I propose we first type what we can
  • In a second PR we makes changes to use Enums instead of NamedTuple

speaking of functions:

  • It's a nightmare to type, I managed in the past to type some of the wrappers but using mostly some Any parameters are they are generics and can be anything.
  • I'll have a look and make some proposals if I find anything better but I don't mind so much if it's ot perfect

Thank you for this contribution, the major goal here is to move forward and to type what we can so we can have a new 6.0.0 release the sooner the better 🙃

Copy link
Collaborator

@lavigne958 lavigne958 left a comment

Choose a reason for hiding this comment

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

Nice work thank you for this.

I have only a few comments regarding some details.

  • About the callable, that's fine to me, I might rework it anyway
  • could you please format your code, by running: tox -e format in order to make it pass the CI, thanks.

gspread/utils.py Outdated Show resolved Hide resolved
gspread/utils.py Outdated Show resolved Hide resolved
gspread/utils.py Outdated Show resolved Hide resolved
@butvinm
Copy link
Contributor Author

butvinm commented May 31, 2023

I updated the PR

gspread/utils.py Outdated Show resolved Hide resolved
@lavigne958 lavigne958 marked this pull request as ready for review June 7, 2023 20:35
Copy link
Collaborator

@lavigne958 lavigne958 left a comment

Choose a reason for hiding this comment

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

sorry I was wrong before, you were right about the type for the default_blank it should be as mentioned in the comment. Users are allowed to pass None as value for default blank.

apart from that I see issues with the named tuples but that will go away anyway so no worries bout them.

I see a couple of issues with the float("inf") which has only be a pain to handle so let's merge it like this (after you revert the default blank type) then I'll have a look if I keep the Inf value of not.

thanks again for your work.

gspread/utils.py Outdated Show resolved Hide resolved
@butvinm
Copy link
Contributor Author

butvinm commented Jun 7, 2023

I also changed type of default_blank at numericise method, because it has same behaviour as numericise_all

Copy link
Collaborator

@lavigne958 lavigne958 left a comment

Choose a reason for hiding this comment

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

looks good to me.

thank you for your contribution.

@lavigne958 lavigne958 merged commit 52c4517 into burnash:feature/release_6_0_0 Jun 8, 2023
@alifeee alifeee mentioned this pull request Jan 26, 2024
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.

2 participants