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

WIP: Add typing to configstore #28

Closed
wants to merge 13 commits into from
Closed

WIP: Add typing to configstore #28

wants to merge 13 commits into from

Conversation

just1602
Copy link

@just1602 just1602 commented Oct 18, 2018

Fixes #25

self._backends += (backend,)

def get_setting(self, key, default=_no_default):
def get_setting(self, key: str, default=_no_default) -> str:
Copy link
Author

Choose a reason for hiding this comment

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

Ici, default devrait être un string. Sauf que si default peut être Union[object, str], ça veut dire que le retour de la méthode peut être lui aussi Union[object, str], mais ce n'est pas du tout ce qu'on veut.

J'aurais tendance à faire un _no_default avec une valeur en string, mais faut trouver un default qui ne se retrouverait pas dans un default. Tu en pense quoi @merwok ?

Copy link
Contributor

Choose a reason for hiding this comment

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

_no_default = '~~!!configstore-no-default!!~~'



Backends = TypeVar('Backends', EnvVarBackend, DotenvBackend,
AwsSsmBackend, DockerSecretBackend)
Copy link
Contributor

Choose a reason for hiding this comment

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

It’s not great to have to import all backends here.

Could we declare and interface or ABC or base type and use that?

Copy link
Author

Choose a reason for hiding this comment

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

I woudl really prefer to declare a base class or an interface. It was my first plan, but I wasn't sure if you'd like it and I saw the TypeVar in the documentation.

My toher questions is since we'll have a backend inteface. could we move all backend in a backends.py file with the Backend class ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Go for an ABC or whatever is recommended by typing / mypy.

I don’t see benefits in moving the concrete backend classes though.

Justin Lavoie added 4 commits October 19, 2018 21:20
This way, it's really easier to make typing work without ugly hack or
long Union typing
There is support for typing in python 2.7 but only in comments and we
don't want this
@@ -63,57 +61,6 @@ jobs:
- store_test_results:
path: ~/reports

test-py35:
Copy link
Author

Choose a reason for hiding this comment

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

Comme python 3.5 est juste en security status et que certaine type hint ne sont pas supporté dedans, mais le sont dans python 3.6 et 3.7, j'ai enlevé le support de 3.5.

@merwok merwok self-assigned this Oct 20, 2018
@@ -6,6 +6,8 @@ __pycache__
/.coverage
/.tox/
/venv/
/.pyre/
.pyre_configuration
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this file live at the repo root?

Copy link
Author

Choose a reason for hiding this comment

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

Normally yes.

Copy link
Contributor

@merwok merwok left a comment

Choose a reason for hiding this comment

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

This is great! Let’s discuss how to type-check duck-typed backend classes.

name: Test with Python 2.7
command: |
venv/bin/tox --sdistonly
venv/bin/tox -e py27 -- --junitxml=~/reports/tox/coverage.xml
Copy link
Contributor

Choose a reason for hiding this comment

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

There’s some config that can be removed from tox.ini too if you want to clean up.

pass

def get_setting(self, key: str) -> Optional[str]:
raise NotImplementedError
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like this to be a real abstract base class, and also keep the duck typing (not require that classes inherit from the base class). We could chat about this on Monday, the background and reasoning could be quite long for a review message!

(Duck typing / virtual subclasses can be handled by typing: https://mypy.readthedocs.io/en/stable/protocols.html#protocol-types )


class EnvVarBackend(Backend):

def get_setting(self, key: str) -> Optional[str]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Great job fixing the param names in get_setting methods!

@merwok merwok changed the base branch from master to main December 8, 2020 23:30
@just1602 just1602 closed this Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add typing
2 participants